如何在iOS项目中添加自定义Framework的引用而非副本
Hey there, let's tackle that "No such module" error you're hitting when referencing your custom Framework without copying it into the project. I've run into this exact issue before, so here are the actionable steps to fix it:
Fix Framework Search Paths
Open your project's Build Settings, search forFramework Search Paths, and add the path to yourframeworksfolder. Using$(SRCROOT)(which points to your project's root directory) makes this reliable—try adding$(SRCROOT)/frameworksand set the path type torecursive(if your framework is nested) ornon-recursive. This tells Xcode exactly where to look for your module.Match Build Configurations
If your project is running in Debug mode but your Framework was built for Release (or vice versa), Xcode might fail to locate the module. Check your scheme's configuration (Product > Scheme > Edit Scheme > Run > Info) and ensure it matches the build configuration used for your Framework. For flexibility, you can configure your Framework to build for both Debug and Release in its own Build Settings.Validate Framework Structure
Right-click your Framework and select "Show in Finder" to check for aModulesfolder containing amodule.modulemapfile. This file is critical for Swift/Clang to recognize the module—if it's missing or malformed, you'll get the "No such module" error. Recompile your Framework if this structure is incomplete.Check Embed Settings
Head to your project's General tab, underFrameworks, Libraries, and Embedded Content. Make sure your Framework is listed here, and set its embed status to Do Not Embed (since you don't want to copy it into the project). If it wasn't added correctly, remove it and re-add it, double-checking that "Copy items if needed" remains unchecked.Clear Xcode Caches & Restart
Xcode's cached build data can cause weird issues like this. RunCommand + Shift + Kto clean the project, thenCommand + Option + Shift + Kto wipe the build folder. Restart Xcode entirely before recompiling—this often resolves hidden cache conflicts.Verify Folder Permissions
Ensure your project has read/write access to theframeworksfolder. If you moved the Framework into your project's root directory, confirm the folder's permissions are set to allow your user account to access its contents.
内容的提问来源于stack exchange,提问作者George Vardikos




