Skip to content

Instantly share code, notes, and snippets.

@ericdke
Last active December 4, 2018 21:21
Show Gist options
  • Save ericdke/556cc47772153801511d to your computer and use it in GitHub Desktop.
Save ericdke/556cc47772153801511d to your computer and use it in GitHub Desktop.
Mac OS X: find computer model identifier
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