Skip to content

Instantly share code, notes, and snippets.

@nh7a
Created February 21, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh7a/de35e185aea085721c5e05499252ed97 to your computer and use it in GitHub Desktop.
Save nh7a/de35e185aea085721c5e05499252ed97 to your computer and use it in GitHub Desktop.
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