Skip to content

Instantly share code, notes, and snippets.

@robinkunde
Created June 16, 2025 17:25
Show Gist options
  • Save robinkunde/715701d26097bad1931832a5d6612bae to your computer and use it in GitHub Desktop.
Save robinkunde/715701d26097bad1931832a5d6612bae to your computer and use it in GitHub Desktop.
withMemoryRebound(capacity)
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