"Poof — and the app crashed": getting to know dyld: Library not loaded: @rpath/libswiftCore.dylib
\n\nHave you ever launched your Swift app, seen a beautiful splash screen, and then — bang! — a black screen and a console full of red text? Sound familiar? If you've ever encountered the message dyld: Library not loaded: @rpath/libswiftCore.dylib, you know that feeling of mild panic. This question has gathered thousands of views on Stack Overflow, and for good reason: the error is tricky but solvable.
In this article, we won't just give you a dry instruction. We'll break down why Swift libraries "get lost" at runtime, how to avoid it, and what to do if you're already in trouble. Let's go!
\n\nWhat is dyld and why is it angry?
\n\ndyld (dynamic link editor) is the dynamic library loader on macOS and iOS. When your app launches, dyld looks for all required libraries at the paths specified in the binary. One such path is @rpath (runtime search path). If a library (e.g., libswiftCore.dylib) is not found at this path, dyld crashes with an error.
Simply put: you told the app "take the book from the @rpath shelf," but the shelf was empty. That's the whole mystery.
\n\nWhy does this happen specifically with libswiftCore.dylib?
\n\nlibswiftCore.dylib is the core of the Swift runtime. No Swift code works without it. The error most often occurs in three cases:
- \n
- You are using Xcode 14+ and the project is configured for an older version of Swift. \n
- You are linking frameworks or CocoaPods that require a specific version of the Swift runtime. \n
- You forgot to enable "Always Embed Swift Standard Libraries" in the build settings. \n
5 ways to fix dyld: Library not loaded: @rpath/libswiftCore.dylib
\n\nLet's move to practice. Below are proven methods, from simple to complex. For each, I'll provide code or settings examples.
\n\n1. Enable "Always Embed Swift Standard Libraries"
\n\nThe most common culprit. If your app doesn't embed Swift libraries in the bundle, dyld won't find them on the device.
\n\nHow to fix:
\n- \n
- Open your project in Xcode. \n
- Select Target → Build Settings. \n
- Find
Always Embed Swift Standard Libraries. \n - Set the value to
Yes. \n
If you use CocoaPods, check that your Podfile doesn't have a line disabling this behavior:
# Bad (may cause the error)\npost_install do |installer|\n installer.pods_project.targets.each do |target|\n target.build_configurations.each do |config|\n config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'\n end\n end\nend\n\n# Good\npost_install do |installer|\n installer.pods_project.targets.each do |target|\n target.build_configurations.each do |config|\n config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'\n end\n end\nend\n\n\n2. Check Swift version compatibility
\n\nIf you've linked a framework built with Swift 5.7, but your project uses Swift 5.5 — hello, error. The Swift runtime is not 100% backwards compatible.
\n\nSolution: ensure all dependencies use the same Swift version. Open Terminal and run:
\n\n# Find out the Swift version for a specific .framework\nstrings MyFramework.framework/MyFramework | grep "Swift"\n# Or check via xcrun\nxcrun swift --version\n\n\nIf the framework was built with a different version, rebuild it or update it.
\n\n3. Clean Derived Data and rebuild the project
\n\nSometimes Xcode caches old library paths. A full rebuild often solves the problem.
\n\n# Delete Derived Data manually\nrm -rf ~/Library/Developer/Xcode/DerivedData