1

I´m able to get the current device right now by checking this:

static func iPhoneModelSize() -> Int{
    switch UIDevice.currentDevice().modelName {
    case "iPhone 4", "iPhone 4S" :
        return 8
    case "iPhone 5", "iPhone 5C", "iPhone 5S" :
        return ...
    case "iPhone 6, iPhone 6s" :
        return ...
    case "iPhone 6 Plus, iPhone 6s Plus" :
        return ...
    default:
        return ...
    }
}

But when I´m using the simulator I always have to change the default value since it´s the simulator, is there any other way to get the current device AND also the current simulator device?

  • 1
    I don't see a `modelName` property on `UIDevice.currentDevice()`, only `model`. – JAL Jan 24 '16 at 22:05
  • 1
    I have included an extension, should have mentioned it my bad. But I hope you get the idea @JAL –  Jan 24 '16 at 22:06
  • The better question is why you think you need this info. It's very rare where you should be worried about which model device your app is running on. There are far more appropriate solutions depending on what problem you are really trying to solve with this. – rmaddy Jan 24 '16 at 23:00

1 Answers1

0

You could check the device height, in that case you will also include the simulator.

static func currentDevice() -> String{
    switch UIScreen.mainScreen().bounds.height {
    case 480 :
        return "iPhone 4/S"
    case 568 :
        return "iPhone 5/S"
    case 667 :
        return "iPhone 6/S"
    case 736 :
        return "iPhone 6 Plus/S"
    default:
        return ""
    }
}
Rashwan L
  • 38,237
  • 7
  • 103
  • 107