Last active
December 4, 2018 21:21
-
-
Save ericdke/556cc47772153801511d to your computer and use it in GitHub Desktop.
Mac OS X: find computer model identifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func modelIdentifier() -> String? { | |
let service: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")) | |
let cfstr = "model" as CFString | |
if let model = IORegistryEntryCreateCFProperty(service, cfstr, kCFAllocatorDefault, 0).takeUnretainedValue() as? NSData { | |
if let nsstr = NSString(data: model, encoding: NSUTF8StringEncoding) { | |
return nsstr as String | |
} | |
} | |
return nil | |
} | |
modelIdentifier() // "iMac14,2�" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment