Last active
October 29, 2023 11:36
-
-
Save vadimpiven/3373bb2592d59560b5d698ba1e2ed7e4 to your computer and use it in GitHub Desktop.
Get macOS machine UUID (Swift 5)
This file contains 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
// 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 | |
).takeUnretainedValue() as? String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits to https://gist.github.com/ericdke/ed2d8bd3d127c25bcc6b