I wonder if, when building an iPhone app for the Simulator, there are special DEFINEs added that allow me to conditionally compile for this case?
If not, I'll have to add my own targets for this case, but I'd rather have an automatic way of detection.
Alternatively, is there a dynamic way to know when my code runs on the Simulator, I mean something that's documented? I've been searching the docs for a while now but had no luck yet.
The simulator does a really lousy job of indicating app performance. In fact it doesn't try. For most things the simulator is much, much faster than an iOS device. It runs your code on an x86 processor, which is much faster than the ARM and has many times more memory.
For iOS, tvOS, and watchOS apps, you can choose a simulated device, under [Platform] Simulators, from the run destination menu next to the scheme menu in the toolbar. To add additional simulators of a product family running older versions of the operating system, choose Add Additional Simulators.
To run your app in Simulator, choose an iOS simulator—for example, iPhone 6 Plus, iPad Air, or iPhone 6 + Apple Watch - 38mm—from the Xcode scheme pop-up menu, and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator on your Mac screen, as shown in Figure 1-1.
Viewing & Testing. When you're in the simulator, click open Safari, click on the URL bar, and you can paste the testing URL using ^⌘V (Edit > Paste Text), then hit enter.
For compile-time check you need TARGET_IPHONE_SIMULATOR defined in TargetConditionals.h
#if TARGET_IPHONE_SIMULATOR // Simulator code #endif
For run-time check you can use for example -model
method in UIDevice. For iPhone simulator it returns iPhone Simulator
string (not sure about iPad simulator though)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With