iOS XCode-Swift构建Profile时class not found,紧急求助(周末将发布App Store)
Hey there, sorry to hear you're hitting this frustrating roadblock right before your App Store release—total bummer. Let's break down why profiling might throw a "class not found" error when a regular build works, and walk through actionable fixes:
Check Build Configuration Mismatches
By default, the Profile action uses the Release configuration (or Debug with optimizations), while your regular Build might be using the unoptimized Debug config. Head toProduct > Scheme > Edit Scheme, select the Profile tab, and confirm the Build Configuration matches what you use for your working Build. If they differ:- Navigate to your target's Build Settings
- Search for
Compile SourcesandLink Binary With Libraries - Double-check the missing class is included in the Profile configuration (not just Debug)
Disable Aggressive Optimizations/Dead Code Stripping
Release builds often enable Dead Code Stripping (DEAD_CODE_STRIPPING = YES) and aggressive optimizations that can accidentally remove classes the compiler thinks are unused. Test by temporarily adjusting these for the Profile config:- In Build Settings, set
Dead Code StrippingtoNO - Set
Optimization LeveltoNone [-O0] - Rebuild and try profiling again. If it works, you'll need to mark the class as explicitly used (e.g., add
@objcif it's referenced via Objective-C, or use@_optimize(none)for the specific class) to prevent it from being stripped in optimized builds.
- In Build Settings, set
Wipe Cached Build Artifacts
Cached derived data or build folder artifacts can cause mismatches between Build and Profile actions. Do a full clean:- Press
Cmd+Shift+Kto clean the build folder - Go to
Xcode > Settings > Locations, click the arrow next to Derived Data, and delete your project's folder - Restart Xcode, then try profiling again
- Press
Validate Dynamic Framework Setup
If the missing class lives in a dynamic framework, ensure it's properly embedded and linked for the Profile configuration:- Go to your target's General tab, scroll to Frameworks, Libraries, and Embedded Content
- Confirm the framework is set to
Embed & Sign(notDo Not Embed) - Check Build Settings to make sure
Framework Search Pathsincludes the framework's location for all configurations
Double-Check Scheme Profile Action Settings
Make sure the Profile action isn't excluding critical targets or files:- Open the scheme editor (
Product > Scheme > Edit Scheme) - Select the Profile tab, then review the Info and Build sections
- Ensure all necessary targets are checked, and no relevant files are marked as excluded from the build
- Open the scheme editor (
Hope one of these fixes gets your profiling up and running so you can squash those crashes before your weekend release!
内容的提问来源于stack exchange,提问作者CoolDocMan

