![]() ![]() If you need to run non-UI code for testing, for instance, there are far more easier ways to achieve what you need, such as creating a macOS target and including all your non-UI stuff in it, and stubbing out the absolutely minimum necessary UI stuff for testing. It is enough to look at how widely the simulator framework has changed over the recent years to get a feel for how hard this would be for non-Apple developers. Legal or otherwise, it would be quite an undertaking, and very likely to break with each change to the system. Theoretically, it is possible to spin up the iOS subsystem partially or fully in a different manner than how the simulator does, but this is most likely infringes on the developer license agreement you signed when installing, and would certainly not be legal for distribution. The IBDesignablesAgentCocoaTouch daemon spins up enough of the iOS subsystem to be able to take a snapshot of your UI every time you make a change in Xcode. The simulator framework provides the runtime needed for all those framework to function in a manner similar to how they do on iOS hardware. Return UIDevice.currentDevice().IOS apps compiled for x86_64 are actually normal macOS apps, just linked against different frameworks. Return NSProcessInfo.processInfo().environment != nil ![]() The Swift compiler will attempt toĭetect, warn, and suggest the use of targetEnvironment(simulator) whenĮvaluating platform conditions that appear to be testing for simulatorĮnvironments indirectly, via the existing os() and arch() platform '#if targetEnvironment(simulator)' can now be used to detect when the build target is a simulator. Swift supports a new platform condition targetEnvironment with a ![]() ![]() In order to work around this warning, see one of the other answers.įrom Xcode 9.3 #if targetEnvironment(simulator) #if (arch(i386) || arch(x86_64)) & os(iOS)Īlso, since the flag is replaced with a 0 or a 1 by the swift preprocessor, if you directly use it in a if/else expression the compiler will raise a warning about unreachable code. This is impossible with a dynamic check, whereas it's trivial with a static check. Say, for example, that you want to have different imports on the device and on the simulator. For instance you won't be able to use it in place where a if/else is syntactically invalid (e.g. Please notice that this is different and slightly more limited than using a preprocessor flag. If you instead are ok with a runtime check, you can inspect the TARGET_OS_SIMULATOR variable (or TARGET_IPHONE_SIMULATOR in iOS 8 and below), which is truthy on a simulator. If you are developing for a simulator other than iOS, you can simply vary the os parameter: e.g.ĭetect the watchOS simulator #if (arch(i386) || arch(x86_64)) & os(watchOS)ĭetect the tvOS simulator #if (arch(i386) || arch(x86_64)) & os(tvOS) The arch(i386) build configuration returns true when the code is compiled for the 32–bit iOS simulator. Latest use, now directly for all in one condition for all types of simulators need to apply only one condition - #if targetEnvironment(simulator)įor more clarification, you can check Swift proposal SE-0190Ĭlearly, this is false on a device, but it returns true for the iOS Simulator, as specified in the documentation: not a runtime if/else) you can't detect the simulator directly, but you can detect iOS on a desktop architecture like follows #if (arch(i386) || arch(x86_64)) & os(iOS) For detailed instructions on how to do to it, see answer. While this answer may work, the recommended solution for a static check (as clarified by several Apple engineers) is to define a custom compiler flag targeting iOS Simulators. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |