Skip to content

Instantly share code, notes, and snippets.

@ericdke
Last active October 31, 2023 05:04
Show Gist options
  • Save ericdke/ed2d8bd3d127c25bcc6b to your computer and use it in GitHub Desktop.
Save ericdke/ed2d8bd3d127c25bcc6b to your computer and use it in GitHub Desktop.
Swift: get the Mac UUID
func getSystemUUID() -> String? {
let dev = IOServiceMatching("IOPlatformExpertDevice")
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev)
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey, kCFAllocatorDefault, 0)
IOObjectRelease(platformExpert)
let ser: CFTypeRef = serialNumberAsCFString.takeUnretainedValue()
if let result = ser as? String {
return result
}
return nil
}
if let uuid = getSystemUUID() {
print(uuid)
}
@Eaffy
Copy link

Eaffy commented May 19, 2020

thank you!

add one

@vadimpiven
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment