Fix: dyld: Library not loaded: @rpath/libswiftCore.dylib Crash

Fix: dyld: Library not loaded: @rpath/libswiftCore.dylib Crash

Written by

in

Quick answer: This crash occurs when Xcode fails to embed the Swift runtime libraries or when code signing validation fails to map the dylib on a physical device. To resolve it, set ‘Always Embed Swift Standard Libraries’ (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:

  1. 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 .app bundle.
  2. Code signature rejection (mmap() error 1): When the error output includes mmap() error 1 or Reason: 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.

  1. Open your project in Xcode and select your main app target under Targets.
  2. Click the Build Settings tab and ensure All and Combined filters are selected.
  3. In the search field, type Always Embed Swift Standard Libraries.
  4. Change the value to Yes for your target (this corresponds to ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES in 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.

  1. Quit Xcode completely.
  2. Open Keychain Access on your Mac.
  3. In the menu bar, select View > Show Expired Certificates.
  4. Search for Apple Worldwide Developer Relations under both the login and System keychains.
  5. Delete any expired WWDR certificates. Keep only active, valid intermediate certificates.
  6. Delete any duplicate or untrusted developer certificates from your login keychain.
  7. 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.

  1. In your target’s Build Settings, search for Runpath Search Paths (LD_RUNPATH_SEARCH_PATHS).
  2. 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.

  1. In Xcode, choose Product > Clean Build Folder (or press Shift + Command + K).
  2. 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
  1. Delete the installed app from your physical test device.
  2. 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_LIBRARIES to Yes.
  • 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.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.