When building an iOS app in Xcode, you may encounter Command CompileStoryboard failed with a nonzero exit code or CompileStoryboard failed. This usually means Interface Builder could not compile a storyboard or XIB because of an invalid class reference, broken outlet or action connection, deployment-target mismatch, malformed storyboard XML, target-membership issue, or stale build data. The key is to inspect the detailed Interface Builder error that appears immediately before the final CompileStoryboard failure.
- Common causes
- Typical error
- How to diagnose the problem
- Solution 1: Check Custom Class and Module
- Solution 2: Remove broken IBOutlet and IBAction connections
- Solution 3: Inspect the storyboard XML
- Solution 4: Check the deployment target
- Solution 5: Clean build data
- Solution 6: Use ibtool to inspect warnings and errors
- Solution 7: Verify Target Membership
- Important note
- Summary
Common causes
- A Custom Class in the storyboard no longer exists or has been renamed
- The Module setting points to the wrong target
- An IBOutlet or IBAction connection still references deleted code
- The storyboard uses settings that are not compatible with the selected deployment target
- The storyboard or XIB XML was damaged during a merge
- DerivedData or Interface Builder caches are stale
- Target Membership is incorrect in a multi-target project
Typical error
The build log often ends with:
Command CompileStoryboard failed with a nonzero exit code
This line is usually only the final failure notice. The more useful error message is typically a few lines earlier in the build log.
How to diagnose the problem
- Open Xcode’s Issue Navigator.
- Expand the CompileStoryboard error.
- Read the messages immediately before the final failure line.
- Open the affected storyboard or XIB in Interface Builder.
- Check Custom Class, Module, outlets, actions, Target Membership, and deployment settings.
- If necessary, open the storyboard as source code and inspect its XML.
Solution 1: Check Custom Class and Module
Select the affected view controller or view in Interface Builder and open the Identity Inspector. Confirm that the Custom Class matches a class that actually exists in the project and that the Module is correct.
If a Swift class was renamed but the storyboard still references the old name, storyboard compilation can fail. In many projects, enabling Inherit Module From Target is appropriate.
Solution 2: Remove broken IBOutlet and IBAction connections
Open the Connections Inspector and look for outlets or actions that point to properties or methods that were removed or renamed. Remove invalid connections and reconnect them to the current code.
@IBOutlet weak var titleLabel: UILabel!
@IBAction func didTapButton(_ sender: UIButton) {
// action
}
Solution 3: Inspect the storyboard XML
If the error started after a Git merge or conflict resolution, right-click the storyboard and choose Open As → Source Code. Check for malformed XML, unresolved conflict markers, or references to objects that no longer exist.
After fixing the XML, reopen the file in Interface Builder and build again.
Solution 4: Check the deployment target
Make sure the project’s iOS Deployment Target, the target’s deployment settings, and the storyboard’s File Inspector settings are consistent. A storyboard that contains unsupported interface features can fail to compile for an older target.
Solution 5: Clean build data
If the storyboard appears valid, stale build data may be responsible. Use Product → Clean Build Folder in Xcode, or clean the project from Terminal and rebuild.
xcodebuild -alltargets clean
Solution 6: Use ibtool to inspect warnings and errors
Xcode uses Apple’s ibtool to process storyboards and XIB files. You can use it from Terminal to display storyboard-related diagnostics.
xcrun ibtool --warnings --errors --notices Base.lproj/Main.storyboard
Adjust the path to match the actual location of your storyboard.
Solution 7: Verify Target Membership
In projects with multiple app targets, make sure the storyboard belongs only to the targets that are supposed to compile it. An incorrect membership can cause a storyboard to reference classes or modules that do not exist in that target.
Important note
Command CompileStoryboard failed with a nonzero exit code is often not the root cause. Always inspect the preceding Interface Builder error before changing project settings. Cleaning build data may help with cache problems, but configuration or connection errors must be fixed directly.
Summary
To fix CompileStoryboard failures in Xcode, first identify the detailed Interface Builder error, then check Custom Class and Module settings, IBOutlet and IBAction connections, deployment target, storyboard XML, and Target Membership. If the configuration looks correct, clean the build data and use ibtool for additional diagnostics.
