I am trying to have a certain block of code only be executed if the users iPhone is of a certain model. I am testing on the iOS Simulator, so I used the iPhoneModel()
function bellow to get the device model for the simulator and printed it to the console and pasted it into the if condition in the compare()
function.
func iPhoneModel() -> String {
var sysinfo = utsname()
uname(&sysinfo) // ignore return value
return NSString(bytes: &sysinfo.machine, length: Int(_SYS_NAMELEN), encoding: NSASCIIStringEncoding)! as String
}
func compare() {
if iPhoneModel() == "x86_64" {
print("It Worked!")
}
}
The iPhoneModel()
function should return an identical string and the statement should be true, but instead it is false. I have even printed both strings to console to check them with my own eyes and they both appear to be identical, yet the computer thinks otherwise. Any ideas why?