Uncategorized Command CompileSwiftSources failed with a nonzero exit code

I got an Xcode error that says "Uncategorized Command CompileSwiftSources failed with a nonzero exit code". I notice that in the toolbar next to the name of my app it says "My Mac" and I can't switch it back to iPhone. Can this be causing the error? How do I fix it?

Accepted Reply

That "archive" contains only your built app, so you can't recover you project from it. If your project is corrupted, then you should get it back from:


— An earlier version of your source code repository, if you're using SCM (source code management) such as GitHub.


— A backed up version, from one of your regular backups (e.g. Time Machine).


If you're not using SCM, I strongly advise you start using it, since it's the easiest way to go back in time in a controlled manner. If you're not doing regular backups (whether or not you use SCM), you will almost certainly have a very, very bad experience one day soon, when you lose everything, not just an Xcode project. 🙂


If you don't have one of those options right now, you may have to recreate the Xcode project from scratch. (However, you shouldn't need to recreate the source files. You already have them, so create a new project and add them to it.)

Replies

>> in the toolbar next to the name of my app it says "My Mac"


That's actually the name of the target (which is often the same as the name of the app), and a target is either macOS or iOS, so you can't switch it to iPhone.


If you have a different target that's for iOS, you can switch to that by clicking on the target name (left side of that popup) rather than the device (right side of that popup).


However, the real problem is your build error. You should go to the build log (Command-9, or "View"->"Navigators"->"Report Navigator"), select the build that has the error icon, then over in the editor pane, select the line that has an error icon. Over to the far right of the selected line is an icon that expands that section of the build log. You should see more information in the expanded build log.


That error isn't something that you'd expect to happen, though, so it's possible that your project file is corrupt, which might also explain why it "magically" changed from iOS to macOS (if it did). If it's corrupt, you might have to go back to an earlier version, or create a new project.

Seen this SO thread? Loads of things it might be, including nothing more than an Xcode bug, w/a few actual success stories that might help, the easiest of which to try is the Product menu w/the option key pressed, choosing to 'clean build folder':


https://stackoverflow.com/questions/46690619/build-fails-with-command-failed-with-a-nonzero-exit-code


Good luck.

Yes, I think the project is corrupt. I archived an earlier version. How do I open up an archived version? I went to organizer, selected the archive and distributed it as development but it saves it as an IPA. The problem with starting a new app is that I can't name it the same name because that name is already linked to an app identifier. How do I get around this?

That "archive" contains only your built app, so you can't recover you project from it. If your project is corrupted, then you should get it back from:


— An earlier version of your source code repository, if you're using SCM (source code management) such as GitHub.


— A backed up version, from one of your regular backups (e.g. Time Machine).


If you're not using SCM, I strongly advise you start using it, since it's the easiest way to go back in time in a controlled manner. If you're not doing regular backups (whether or not you use SCM), you will almost certainly have a very, very bad experience one day soon, when you lose everything, not just an Xcode project. 🙂


If you don't have one of those options right now, you may have to recreate the Xcode project from scratch. (However, you shouldn't need to recreate the source files. You already have them, so create a new project and add them to it.)