My setup
- macOS 10.14 Mojave
- Xcode 10.3
- cocoapods 1.7.5
None of the answers work for me, although some gave partial clues. In my case, the root cause was that I customized my build product paths **after running `pod install`**.
If you run cocoapods right after creating an Xcode project, then it usually works if you open the generated Xcode `.xcworkspace` instead of the `.xcodeproj`.
Funny things happen if you start tweaking your build product paths **after generating the workspace**. Because the generated Pods project and its target all refer to your old Xcode project settings.
In my case, my trouble came from:
- I prefer all my build products sitting under the project folder `$(SRCROOT)/build/$(CONFIGURATION)/$(EFFECTIVE_PLATORM_NAME)`. So I went ahead and changed my `Pre-configuration Build Products Path` to it .... **AFTER doing `pod install`**.
Now, the generated `Pods` project, including all its Framework target, still points to the old location, so both the header import and linking of your own project will fail (you'd see `Command PhaseScriptExecution failed with a nonzero exit code` when `No such module` is fixed).
**The fix:**
- Delete all Pods stuff including the workspace.
- Regenerate `Pods` project and workspace with `pod install`. However, cocoapods hardcodes the build product path to `${SRCROOT}/../build` and `Pre-configuration Build Products` to `$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)` in my case, which usually points to a temporary `~/Library/Developer` subfolder . Still not quite right. Then ....
- Make sure the `Framework Search Path` and `Header Search Path` of my own project cover the above paths.
- Tweak `Pods` project setting and all dependency Framework's `Pre-configuration Build Products Path` to use my preferred paths.
The moral lesson: **Always regenerate Pods and verify the key result paths whenever you touch paths in Xcode project settings.**
**UPDATE**
With Xcode 11, Apple finally removed the confusing "Pre-configuration Build Products Path". To customize the build product paths, use `Locations` in Xcode preferences with global relative paths pre-baked.