Why this happens
The message is coming from the linker, not from Swift. When you build for a simulator destination, every linked framework must contain a binary slice compiled for the simulator platform. If the only slice inside Foo.framework/Foo was compiled for iOS device, the linker stops with:
Building for iOS Simulator, but the linked framework 'Foo.framework' was built for iOS.
There are two very different situations behind that one line.
The first is genuine: the framework was archived for generic/platform=iOS only, and nobody ever built a simulator variant. That is common with vendor SDKs and with frameworks you build yourself and copy into the project by hand.
The second is a project-file quirk that showed up around Xcode 12.3. The VALIDATE_WORKSPACE build setting was missing from project.pbxproj entirely, and Xcode resolved the framework incorrectly as a result. Because the key is absent, Build Settings still displays NO — that is just the default value of a setting that was never written. Touching the setting forces Xcode to serialize it into the project file, and the build starts working again. That is why the accepted fix looks like superstition but is really a project-file repair.
How to fix it
1. Toggle Validate Workspace (the Xcode 12.3 fix)
- Select your app target in the Project navigator.
- Open the Build Settings tab and make sure All is selected, not Basic.
- Search for
Validate Workspace. - Set it to Yes.
- Build for the simulator.
- Optionally set it back to No.
The value is not what matters — the presence of the key in project.pbxproj is. If you diff the project file before and after, you will see a single added line:
VALIDATE_WORKSPACE = NO;
Commit that change so your teammates and CI get the same repair without repeating the dance. If you are on a much newer Xcode and the setting is already present, this step will do nothing for you and you should move on to step 2.
2. Check what is actually inside the framework
Before changing anything else, confirm whether a simulator slice exists. lipo alone is not enough, because device and simulator builds are both arm64 — the architecture name does not tell you the platform. Use vtool instead:
xcrun vtool -show-build Foo.framework/Foo
You will get one LC_BUILD_VERSION block per slice. Look at the platform line:
platform IOS
platform IOSSIMULATOR
If you only see IOS, the framework is device-only and no build setting will save you. If you see both, the problem is on the Xcode side — check your Framework Search Paths and delete Derived Data, because a stale copy of the device build may be getting picked up from an earlier location.
3. Rebuild the framework as an XCFramework
This is the real fix, and it is what you should ship to anyone consuming your framework. An .xcframework is a folder that wraps one .framework per platform, so Xcode picks the right slice automatically and the error cannot occur.
Archive both destinations, then combine them:
xcodebuild archive \
-project MyFramework.xcodeproj \
-scheme MyFramework \
-destination "generic/platform=iOS" \
-archivePath build/ios.xcarchive \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild archive \
-project MyFramework.xcodeproj \
-scheme MyFramework \
-destination "generic/platform=iOS Simulator" \
-archivePath build/iossim.xcarchive \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework build/ios.xcarchive/Products/Library/Frameworks/MyFramework.framework \
-framework build/iossim.xcarchive/Products/Library/Frameworks/MyFramework.framework \
-output build/MyFramework.xcframework
Drop the resulting MyFramework.xcframework into the project and remove the old .framework reference. BUILD_LIBRARY_FOR_DISTRIBUTION=YES is worth keeping on: it emits a module interface so the binary stays usable across Swift compiler versions.
4. If the framework is a third-party binary
You cannot fix a vendor’s device-only framework from your side. Ask for an XCFramework build, or check whether a newer release already ships one. Adding EXCLUDED_ARCHS or hand-editing project.pbxproj to point at a different path only moves the failure to a different error message.
5. Clean up after the fix
Once the build succeeds, delete Derived Data and rebuild once from scratch to make sure the fix is real and not a cached artifact:
rm -rf ~/Library/Developer/Xcode/DerivedData
How to prevent it
- Distribute frameworks as
.xcframework, never as a bare.frameworkfolder. - Keep the archive script in the repo so the simulator slice is never forgotten.
- Run
xcrun vtool -show-buildon any binary before adding it to a project. - Do not hand-edit
project.pbxproj; change settings through the Xcode UI so the file stays consistent. - Commit
project.pbxprojchanges immediately after any build-setting fix, so CI inherits them.
FAQ
Do I have to leave Validate Workspace set to YES?
No. The setting only needs to exist in the project file. Setting it to YES and back to NO writes the key and leaves you on the default behaviour, which is what most projects want.
Why does the same framework work in my other project?
Compare the two project.pbxproj files. The working project most likely already contains the VALIDATE_WORKSPACE key, or it links a different build of the framework that happens to include a simulator slice. Diffing the two files usually shows the difference in one line.
Will any of this affect device builds?
No. Toggling Validate Workspace changes nothing about how the app is compiled or signed, and an XCFramework simply adds a simulator slice alongside the device slice you already had.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
