Last active
February 2, 2019 16:23
-
-
Save jamesonthecrow/aafde86f5445e192ccb85757ab5ff3b8 to your computer and use it in GitHub Desktop.
Fritz Model Tags
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
private var machineIdentifier: String { | |
// Returns a machine identifier string. E.g. iPhone10,3 or iPhone7,1 | |
// A full list of machine identifiers can be found here: | |
// https://gist.github.com/adamawolf/3048717 | |
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier } | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
return withUnsafeMutablePointer(to: &systemInfo.machine) { | |
ptr in String(cString: UnsafeRawPointer(ptr).assumingMemoryBound(to: CChar.self)) | |
} | |
} | |
func getTagFromMachineIdentifier(machineIdentifier: String) -> String { | |
// Remove all non-number values | |
var stringArray = machineIdentifier.components(separatedBy: CharacterSet.decimalDigits.inverted) | |
// Filter non-number values | |
stringArray = stringArray.filter { $0 != "" } | |
let majorVersion = Int(stringArray[0])! | |
// iPhone 8, X, and XS get a large models. | |
if majorVersion >= 10 { return "large"} | |
// iPhone 7 and less get small models. | |
if majorVersion <= 7 { return "small"} | |
// All other devices get the medium model. | |
return "medium" | |
} | |
// Usage: | |
// getTagFromMachineIdentifier(machineIdentifier: "iPhone10,2") | |
// >> "large" | |
// getTagFromMachineIdentifier(machineIdentifier: "iPhone6,1") | |
// >> "small" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment