Skip to content

Instantly share code, notes, and snippets.

@vadimpiven
Last active October 29, 2023 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadimpiven/3373bb2592d59560b5d698ba1e2ed7e4 to your computer and use it in GitHub Desktop.
Save vadimpiven/3373bb2592d59560b5d698ba1e2ed7e4 to your computer and use it in GitHub Desktop.
Get macOS machine UUID (Swift 5)
// SPDX-License-Identifier: MIT
// MIT Software License: https://opensource.org/licenses/MIT
// Copyright Vadim Piven <vadim@piven.tech>
import Foundation
import IOKit
func getSystemUUID() -> String? {
let platformExpert = IOServiceGetMatchingService(
kIOMainPortDefault,
IOServiceMatching("IOPlatformExpertDevice")
)
guard platformExpert != 0 else { return nil }
defer { IOObjectRelease(platformExpert) }
return IORegistryEntryCreateCFProperty(
platformExpert,
kIOPlatformUUIDKey as CFString,
kCFAllocatorDefault,
0
).takeUnretainedValue() as? String
}
@vadimpiven
Copy link
Author

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