Created
February 21, 2019 22:55
-
-
Save nh7a/de35e185aea085721c5e05499252ed97 to your computer and use it in GitHub Desktop.
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
extension UIDevice { | |
private static func sysctl(by name: String) -> String { | |
return name.withCString { | |
var size = 0 | |
sysctlbyname($0, nil, &size, nil, 0) | |
var value = [CChar](repeating: 0, count: size) | |
sysctlbyname($0, &value, &size, nil, 0) | |
return String(cString: value) | |
} | |
} | |
private struct HW { | |
static let machine = sysctl(by: "hw.machine") | |
} | |
var machine: String { | |
return HW.machine | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment