Why Won’t My Xcode Project Build?
It’s frustrating to click the Run button in Xcode and find that your project won’t build and run. Xcode initially shows you a message like Command CompileSwiftSources failed with a nonzero exit code
, which really doesn’t help much. How do you find where the error is so you can fix it and run your project?
Get a List of the Errors
The first step to figuring out why your project won’t build is to find the compiler errors in your project. Open Xcode’s issue navigator by pressing Cmd–5.
The issue navigator shows the compiler errors in your project. Select an error to show the line where the error is.
Seeing More Detailed Information about an Error
To see more detailed information about a compiler error, open the report navigator by pressing Cmd–9. Select a build from the report navigator to see the build steps and errors for that specific build.
Click the Log button (the small button with the horizontal lines) to see a detailed log of that particular build step.
Tips for Fixing Errors
You found the compiler errors in your project. How do you fix them?
I can’t tell you specifically how to fix the errors because I can’t see your code. But I have some general tips to help you fix the compiler errors in your Xcode projects.
Make Sure Argument Types Match
When calling functions, make sure the data types for the function arguments match. When the argument types don’t match, you get a compiler error message like the following:
Can’t convert value of type X to expected argument type Y
Where X
and Y
data types.
If a function takes an integer as the first argument and you pass a string, you’re going to get the Can't convert value
compiler error.
Check for Typos
If I make a typographical error in this article, you’ll still be able to read the article. But if you make one small typo in your code, the project won’t build.
Make sure you spell function names correctly when calling them. If you have a function called doSomething
and you call it like the following:
doSomethng()
You are going to get a compiler error because you made a typo when calling the function. There is no doSomethng
function.
Make sure that you spell variable names correctly when accessing them. If you have a player
variable in your app and misspell it,
move(playr)
You are going to get a compiler error because there is no playr
variable.
Make sure each left brace, bracket, parenthesis, and quotation mark has a matching right one. An extra left or right brace can lead to compiler errors with bizarre messages.
Import Missing Modules
Make sure you import the modules for the frameworks your app uses. If you’re writing an app that works with PDF documents, you must import the PDFKit framework to call its functions in your app.
import PDFKit