1

I am using a framework called EyeVerify that is built only for the device architecture, and I want to exclude it when running my app on the iOS Simulator. I also don't want any of the code related to the framework to execute while running the app on the iOS Simulator, since presumably it would cause compilation errors.

I've tried the answer posted at this SO topic, but it hasn't worked for me; I receive compilation errors relating to the framework objects not being found. The framework is in Objective-C, and my project is entirely in Swift. Here is what I've tried:

In my bridging header, I nested the import statements in a conditional:

#if !(TARGET_OS_SIMULATOR)
    #import "EyeVerifyLoader.h"
    #import <EyeVerify/EyeVerify.h>
    #import <EyeVerify/EVLicense.h>
#endif

I excluded all of the subclasses that are used only with the framework, like so:

#if !(TARGET_OS_SIMULATOR)
    class EnrollViewController : UIViewController, EVAuthSessionDelegate
    {
        let ev:EyeVerify! = EyeVerifyLoader.getEyeVerifyInstance()
        
        ...
    }
#endif

I excluded all of the code snippets that perform actions using the framework, like so:

#if !(TARGET_OS_SIMULATOR)
    let eyeVerifyLoader:EyeVerifyLoader = EyeVerifyLoader()
    eyeVerifyLoader.loadEyeVerifyWithLicense("test")
#endif

I set the framework to Optional in the Xcode Target Settings (Project Settings > Build Phases > Link Binary with Libraries). Both frameworks in the Embed Frameworks section are apparently required for the framework to function.

enter image description here

When I try to compile, I receive error messages that some types are undeclared, such as EyeVerify in EnrollViewController (see above).

What am I missing?

SOLUTION

It turns out that TARGET_OS_SIMULATOR is not available as a preprocessor macro in Swift according to Apple (scroll down to the Preprocessor Directives section). I found this SO question, which provided me with a solution. I replaced all instances of this macro:

#if !(TARGET_OS_SIMULATOR)

with this:

#if !((arch(i386) || arch(x86_64)) && os(iOS))

Then I removed the macro from my bridging header, as it was not able to interpret it. After that, everything is working great!

Thank you!

Community
  • 1
  • 1
Alexander
  • 3,959
  • 2
  • 31
  • 58
  • This is not a duplicate of the marked question because I am not asking the same question. My question involves more than just the preprocessor macro. – Alexander May 06 '16 at 15:10
  • In any case, I replaced all of my `#if !(TARGET_OS_SIMULATOR)` statements with `#if !((arch(i386) || arch(x86_64)) && os(iOS))`, and it is now working. Thank you! – Alexander May 06 '16 at 15:39

0 Answers0