Search code examples
iosxcodeios-simulatorstatic-libraries

Xcode build error - missing required architecture i386


I know this means that a 3rd party component doesn't run on the simulator:

ld: warning: ignoring file /MyApp/SomeComponent.include/SomeComponent.framework/SomeComponent, missing required architecture i386 in file /MyApp/SomeComponent.include/SomeComponent.framework/SomeComponent (2 slices)
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_SomeComponent", referenced from:
      objc-class-ref in MyViewController.o
ld: symbol(s) not found for architecture i386

But, I don't want to be excluded from ever running the app again on the simulator. The 3rd party component is only required when pushing a button in a certain part of the app. I still want to be able to run the rest of the app in the simulator.

How can I get the compiler to ignore this if I'm running in the simulator?


Solution

  • You could conditionally compile the code using that framework:

     #if !TARGET_IPHONE_SIMULATOR
     // Code using "SomeComponent" that should be compiled for iOS device only ...
     #endif
    

    Alternatively, you could "weakly link" against the framework (as described in "Using Weakly Linked Classes in iOS" and check the availability of the class at runtime:

    if ([SomeComponent class]) {
        // Create an instance of the class and use it.
    } else {
        // Alternate code path to follow when the
        // class is not available.
    }