How do I fix 'building for iOS Simulator, but linking in object file built for iOS' in Xcode/Swift?

When you encounter the error message 'building for iOS Simulator, but linking in object file built for iOS' in Xcode while working with Swift, it typically indicates a mismatch between the architectures for your build configuration. Below are steps to resolve this issue:

Fixing the Linking Error in Xcode

  1. Check Your Target's Build Settings:
  2. Navigate to your Xcode project, select your target, and go to the 'Build Settings' tab. Ensure that the 'Architectures' and 'Valid Architectures' settings are set correctly for both simulator and device.

  3. Check the Frameworks or Libraries:
  4. If you're using third-party frameworks or libraries, make sure they are compiled for both the device and simulator. You can often find simulator-compatible versions or compile them yourself.

  5. Clean and Rebuild the Project:
  6. Sometimes, residue from previous builds can cause this error. Use Shift + Command + K to clean the build folder and then Command + B to rebuild the project.

  7. Use CocoaPods with the Correct Settings:
  8. If you are using CocoaPods, ensure the Podfile is set up correctly to include both simulator and device architectures. Update and install your pods with pod install.

Example Code for Podfile Configuration

platform :ios, '10.0' use_frameworks! target 'YourApp' do pod 'SomeFramework' end

building for iOS Simulator linking error in Xcode Swift compilation issues Xcode build settings iOS Frameworks compatibility