1

Before ios9 I checked the model name of the device to check if the app was running in simulator or not.

if UIDevice.currentDevice().model != "iPhone Simulator" {
    // Device
}
else {
    // Simulator
}

But now with xcode7 and ios9 Swift2.0 the simulator's modelname is now just iPhone which my real divice is too.

My dirty method no longer works, what is the better solution?

Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • 2
    Have a look to this solution: http://stackoverflow.com/questions/24869481/detect-if-app-is-being-built-for-device-or-simulator-in-swift – Pablo A. Sep 24 '15 at 10:24

1 Answers1

-1

You could do

#if (TARGET_IPHONE_SIMULATOR)
    NSLog(@"Running on simulator");

#else
   NSLog(@"Running on device");

#endif

TARGET_IPHONE_SIMULATOR tells you if you're in the iPhone simulator.

TARGET_OS_IPHONE tells you that you're working on the iPhone instead of MacOS.

IronManGill
  • 7,222
  • 2
  • 31
  • 52