Xcode9项目导入DisplaySwitcher失败:安装Pod仍提示模块不存在
Troubleshooting "No such module 'DisplaySwitcher'" in Swift
Hey there, let's work through this frustrating module-not-found issue together—totally get how confusing this can be when you're just starting out with Swift and CocoaPods! Here are some step-by-step checks and fixes tailored for beginners:
1. Double-check you're opening the right project file
This is the most common gotcha for new CocoaPods users:
- After running
pod install, CocoaPods creates a.xcworkspacefile (not the original.xcodeproj). Make sure you're opening this workspace file every time you work on the project—if you open the old.xcodeproj, Xcode won't see the installed pods at all.
2. Verify your Podfile and re-run a clean installation
- Open your Podfile and confirm it has the line:
pod 'DisplaySwitcher'(watch out for typos here!). - If it looks correct, run these commands in your project's root directory to wipe old pod references and start fresh:
pod deintegrate pod installpod deintegrateremoves all existing pod links, which fixes weird leftover issues from previous installs.
3. Fix Xcode's Build Settings inheritance
Sometimes Xcode fails to pick up pod settings automatically:
- Open your workspace, select your main project target (not the Pods target) in the left sidebar.
- Go to the Build Settings tab, search for Framework Search Paths.
- Ensure
$(inherited)is listed here, and set to Recursive. - Next, search for Other Linker Flags—again, make sure
$(inherited)is present in this list.
4. Clear cached build files
Corrupted cached data often causes odd errors:
- Press
Cmd + Shift + Kto clean your project. - Go to Xcode > Settings > Locations, click the arrow next to the Derived Data path, and delete the folder for your project to clear all cached build files.
- Restart Xcode, open the workspace, and try building again with
Cmd + B.
5. Confirm the pod is actually installed
Quickly check your project directory:
- Open the
Podsfolder—you should see aDisplaySwitchersubfolder with the module's source code or framework. If it's missing, runpod install --verbosein the terminal; this shows detailed logs to spot issues like network errors or version conflicts.
Your Code Reference
import UIKit import DisplaySwitcher class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
Attached Screenshots
内容的提问来源于stack exchange,提问作者Alex Snell
相关产品推荐
相关产品推荐

