1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOSのバージョン番号を取得する方法一覧

Posted at
//OSX 10.10以降
print(ProcessInfo.processInfo.operatingSystemVersion)
//OperatingSystemVersion(majorVersion: 10, minorVersion: 12, patchVersion: 5)
print(ProcessInfo.processInfo.operatingSystemVersion.majorVersion)
//10
print(ProcessInfo.processInfo.operatingSystemVersion.minorVersion)
//12
print(ProcessInfo.processInfo.operatingSystemVersion.patchVersion)
//5


print(ProcessInfo.processInfo.operatingSystemVersionString)
//Version 10.12.5 (Build 16F73)

if let dict: NSDictionary = NSDictionary(contentsOfFile: "/System/Library/CoreServices/SystemVersion.plist") {
    if let version = dict.object(forKey: "ProductVersion") as? String {
        print(version)
    }
}
//10.12.5

NSProcessInfo

    /* Human readable, localized; appropriate for displaying to user or using in bug emails and such; NOT appropriate for parsing */
    open var operatingSystemVersionString: String { get }

    
    @available(OSX 10.10, *)
    open var operatingSystemVersion: OperatingSystemVersion { get }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?