Skip to content

Commit edd5196

Browse files
authored
Merge pull request #79 from dmace2/fixSystemNameXcode14
Fix Xcode 14 System.name crashing on app launch
2 parents 7c96e96 + 94f1044 commit edd5196

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

Sources/System.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ class System {
2727
static var name: String? {
2828
var systemInfo = utsname()
2929
uname(&systemInfo)
30-
31-
if let identifier = String(cString: &systemInfo.machine.0, encoding: .ascii) {
32-
// Simulator Check
33-
if identifier == "x86_64" || identifier == "i386" {
34-
return ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]
30+
let identifier = withUnsafePointer(to: &systemInfo.machine, {
31+
$0.withMemoryRebound(to: CChar.self, capacity: Int(_SYS_NAMELEN)) {
32+
ptr in String(cString: ptr)
3533
}
36-
37-
return identifier
34+
})
35+
// Simulator Check
36+
if identifier == "x86_64" || identifier == "i386" || identifier == "arm64" {
37+
return ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"]
3838
}
39-
40-
41-
return nil
39+
return identifier
4240
}
4341
}

0 commit comments

Comments
 (0)