You see an awesome cocoapod you want to include in your project. So you add a code to your podfile telling it to import the cocoapod, you run “pod install” on your terminal to begin the import process, and voila, the cocoapod now inserted to your project. But when you add the namespace “import framework” on top of your Swift file, Xcode said “Cannot Load Underlying Module For <Framework>”.
The easiest explanation is that because you just import the cocoapod, it still hasn’t been built yet, while the other cocoapods in your project have. Therefore, Xcode sometimes overlooks that there is one or two cocoapods that are new.
- Optional: If there’s any, comment out any “import <framework>” statement
In this abnormal state, this statement may gets processed first before Xcode process whether there are any unbuilt pods or not.
- Optional: Clean up the build folder.
This will force Xcode to rebuild everything from scratch, and not playing favorite.
- Optional: Completely quit Xcode, and reopen it, then reopen the project again.
Sometimes the issue is that the Xcode editor can’t let go of the mistakes in the past.
- Rebuild the project.
- Optional: Uncomment all the “import <framework>” earlier.
- Run the project.
So actually the solution to this is just do rebuild first, not run. The optional steps are there if you have run the solution without the optional steps and it’s still not working. For me, I had to clean build folder and close the Xcode, but I didn’t have to comment out the “import <framework” statement. But some people did have to.
Sources / Read More
- Adding Alamofire as a framework and commiting it to Git (#122)
- Cannot load underlying module for ‘Alamofire’ (#441)