Swift报错No such module Parse:仅ViewController中出现该问题求助
Hey Daniel, sorry to hear this Parse module issue is blocking your progress—let’s break down some targeted fixes since it’s only happening in your ViewController:
Check ViewController’s Target Membership
Open yourViewController.swiftfile, then look at the right-side File Inspector. Scroll down to the Target Membership section and make sure your main app target (and any test targets you use) are checked. Sometimes files accidentally get removed from the target, which breaks module resolution just for that file.Verify Parse Installation & Target Integration
Double-check how you installed Parse, since setup steps vary by tool:- For CocoaPods: Confirm your
Podfileincludespod 'Parse', runpod installagain, and make sure you’re opening the.xcworkspacefile (not.xcodeproj)—this is a super common mistake! - For Swift Package Manager: Go to your project settings → Package Dependencies, ensure Parse is added and linked to your main target. Try removing it and re-adding if needed.
Also, double-check your import line in ViewController isimport Parse(capital P matters—no typos allowed!).
- For CocoaPods: Confirm your
Clean Build Cache & Derived Data
Xcode’s cached files often cause weird module errors. Do this:- Press
Cmd + Shift + Kto clean the build folder. - Press
Cmd + Option + Shift + Kto clear derived data. - Close Xcode, delete the project’s folder in
~/Library/Developer/Xcode/DerivedData, then reopen and rebuild.
- Press
Check for Naming Conflicts or File Corruption
- Make sure your ViewController doesn’t share a name with any file in the Parse framework (e.g.,
ParseViewController.swiftcould confuse Xcode). - Try creating a brand new ViewController file, copy your original code into it, and test the import. Sometimes individual files get corrupted in subtle ways that cause module issues.
- Make sure your ViewController doesn’t share a name with any file in the Parse framework (e.g.,
Test Import in Other Files
If importing Parse works in AppDelegate or a new blank Swift file, the problem is isolated to your original ViewController. The new file test above should help confirm this.
内容的提问来源于stack exchange,提问作者Daniel.P

