Skip to content

Instantly share code, notes, and snippets.

@vadimpiven
Last active July 16, 2025 20:55
Show Gist options
  • 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 <[email protected]>
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
).takeRetainedValue() as? String
}
@noah-nuebling
Copy link

๐Ÿ‘๐Ÿ˜Ž

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