ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES) to ‘Yes’ in your target’s Build Settings, verify that Apple Worldwide Developer Relations certificates in Keychain Access are valid, and clean your build folder.Why this happens
The dyld: Library not loaded: @rpath/libswiftCore.dylib runtime exception occurs during app launch when the dynamic linker (dyld) cannot find or map the required Swift runtime libraries. While modern iOS releases include Swift in the OS runtime, apps with mixed Objective-C and Swift targets, embedded frameworks, or older deployment targets require Swift dylibs bundled into the application bundle’s Frameworks/ directory.
Two root causes trigger this specific failure:
- Missing embedded runtime: If an Objective-C main app consumes a Swift framework, or if an app extension uses Swift, Xcode may disable standard library copying. The compiled binary references
@rpath/libswiftCore.dylib, but the file is absent from the installed.appbundle. - Code signature rejection (
mmap() error 1): When the error output includesmmap() error 1orReason: no suitable image found, the file exists in the bundle, but the iOS kernel refuses to map it into memory. This happens when the signing certificate used to sign embedded dylibs has an invalid chain of trust, expired Apple Worldwide Developer Relations (WWDR) intermediate certificates exist in Keychain Access, or the provisioning profile lacks the necessary entitlement to load third-party dynamic libraries.
How to fix it
1. Enable Always Embed Swift Standard Libraries
If your primary target is written in Objective-C but uses Swift dependencies, Xcode does not always embed the Swift runtime by default.
- Open your project in Xcode and select your main app target under Targets.
- Click the Build Settings tab and ensure All and Combined filters are selected.
- In the search field, type
Always Embed Swift Standard Libraries. - Change the value to Yes for your target (this corresponds to
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YESin project configuration files).
If you maintain older projects using legacy build settings, this key was previously called Embedded Content Contains Swift Code (EMBEDDED_CONTENT_CONTAINS_SWIFT).
2. Remove Expired WWDR Certificates from Keychain Access
If you see mmap() error 1, the dynamic library was copied into the bundle, but the device rejected its code signature.
- Quit Xcode completely.
- Open Keychain Access on your Mac.
- In the menu bar, select View > Show Expired Certificates.
- Search for
Apple Worldwide Developer Relationsunder both the login and System keychains. - Delete any expired WWDR certificates. Keep only active, valid intermediate certificates.
- Delete any duplicate or untrusted developer certificates from your login keychain.
- Reopen Xcode, connect your device, and allow Xcode to renegotiate provisioning.
3. Verify Runpath Search Paths
The dynamic linker looks for @rpath tokens using the search paths defined in your build settings. If @executable_path/Frameworks is missing, dyld cannot resolve @rpath/libswiftCore.dylib.
- In your target’s Build Settings, search for Runpath Search Paths (
LD_RUNPATH_SEARCH_PATHS). - Verify that the following paths are listed:
$(inherited)
@executable_path/Frameworks
@loader_path/Frameworks
If your target is an App Extension (like a Widget or Share extension), ensure @executable_path/../../Frameworks is included so the extension can resolve libraries embedded in the parent app bundle.
4. Delete DerivedData and Clean Build Folder
Stale dylib signatures in intermediate build folders can persist across rebuilds.
- In Xcode, choose Product > Clean Build Folder (or press Shift + Command + K).
- Delete derived data by navigating to Xcode > Settings > Locations and clicking the arrow next to the Derived Data path, or run this terminal command:
rm -rf ~/Library/Developer/Xcode/DerivedData
- Delete the installed app from your physical test device.
- Rebuild and run the project.
How to prevent it
- Keep intermediate certificates current: Periodically check Keychain Access for expired developer relations certificates, especially after system migrations.
- Configure host app embedding: Whenever introducing a Swift-based CocoaPod, Swift Package, or dynamic framework into an Objective-C host application, immediately set
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIEStoYes. - Avoid manual framework manipulation: Rely on Xcode’s Frameworks, Libraries, and Embedded Content section rather than manual Run Script copy phases to ensure dynamic libraries receive proper codesigning during compilation.
FAQ
Why does this error happen on a physical device but not in the Simulator?
The Simulator runs on macOS architecture, where code signing enforcement and dynamic library sandboxing are significantly more permissive. Physical devices enforce strict kernel-level signature validation via mmap(), causing builds with invalid intermediate certificates to fail at runtime.
Do pure Swift projects targeting modern iOS versions need this setting?
No. Since iOS 12.2 and Swift 5, the Swift standard library is stable and built directly into the iOS operating system. Modern pure-Swift apps running on supported iOS versions no longer need to bundle libswiftCore.dylib.
What does “mmap() error 1” mean in the dyld output?
error 1 corresponds to EPERM (Operation not permitted). The iOS kernel blocked the process from loading the dynamic library into memory because the embedded file’s digital signature failed validation against the provisioning profile on the device.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
