Created
June 16, 2025 17:25
-
-
Save robinkunde/715701d26097bad1931832a5d6612bae to your computer and use it in GitHub Desktop.
withMemoryRebound(capacity)
This file contains hidden or 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
var systemInfo = utsname() | |
uname(&systemInfo) | |
// capacity = 1 | |
let modelIdentifier1 = withUnsafePointer(to: &systemInfo.machine) { | |
$0.withMemoryRebound(to: CChar.self, capacity: 1) { ptr in | |
String(cString: ptr) | |
} | |
} | |
// actual capacity | |
let modelIdentifier2 = withUnsafePointer(to: &systemInfo.machine) { | |
$0.withMemoryRebound(to: CChar.self, capacity: MemoryLayout.size(ofValue: $0)) { ptr in | |
String(cString: ptr) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment