Search code examples
iosmacosbuildingxcode14macos-ventura

Unable to Build mac project in XCode14.0/14.1 with macOS ventura


I have recently updated to macOS 13.0 and for that minimum XCode Version required is 14.x series. But my existing project never getting successfully building. Its getting stuck at some point. enter image description here

Its not getting failed. Build process screenshot is attached below. Its not pointing to any specific class. Seems like there are lots of classes which are getting compiled successfully at last but still build process is stuck at some point:

enter image description here

Seen similar threads like below on apple pages but nothing seems working. Does anyone got resolution?

Xcode 14 project compile error

XCode 14 compile errors immediately disappear or do not appear at all


Solution

  • Something similar has happened to me in the past on a number of occasions. If the Swift compiler is hanging mid-build, usually the issue is that there is some expression that is too complex for Swift to do the type inference on.

    What you need to do is first find the exact statement that is causing the hang. This is how I do it:

    First find out which source file is causing the problem. Look at the build log to figure this out (the build log can be located by looking at the reports navigator 9 ). Find the build log and click on it. The build log will appear in an editor window. Clicking on a Build Log

    One of the compiles will still be in progress and its file is the one you want.

    The next thing to do is comment out all the code and recompile. This time the compilation will finish (if you have the right file, or there is only one) but probably with a lot of errors. Then you add the code back in, function by function, until one of them causes the compilation to hang again. If it's not obvious which line of the function is causing the problem, comment it out again and then add the lines back one by one until the compilation breaks again.

    Once you have located the line, you need to simplify the type inference on that line. If it's a closure, try adding an explicit declaration for its parameters and return type. If it involves some complex array, try adding a type annotation to its declaration. Also try breaking down complex expressions into multiple simpler expressions.

    There's no one size fits all answer to this but usually, once you have located the exact line that is causing the problem, it should be reasonably obvious how to fix it.