Skip to content

Instantly share code, notes, and snippets.

@jamesonthecrow
Last active February 2, 2019 16:23
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 jamesonthecrow/aafde86f5445e192ccb85757ab5ff3b8 to your computer and use it in GitHub Desktop.
Save jamesonthecrow/aafde86f5445e192ccb85757ab5ff3b8 to your computer and use it in GitHub Desktop.
Fritz Model Tags
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