💬

Community Forums

Xcode Build Errors After Latest Update

Posted by: John Appleseed Views: 1,234 Replies: 5
JA
John Appleseed

Hi everyone,

I've just updated Xcode to the latest version (15.0.1) and now my project is throwing a bunch of build errors that it never had before. The errors seem to be related to Swift 5.9 features and some new deprecations.

Here's a snippet of one of the main errors I'm getting:

1error: cannot find 'async' in scope 2 public func fetchData() async throws -> [Item] { 3 ^~~~~ 4 This diagnostic occurred in the owner of a 'func fetchData()' declaration

Has anyone else encountered this issue after the update? Any tips on how to resolve it quickly would be greatly appreciated!

SK
Sarah Kim

Re: Xcode Build Errors After Latest Update

Hey John,

I had a similar problem! It seems like some older Swift syntax that was previously tolerated is now flagged more strictly. For the `async` error, make sure your target's Swift Language Version is set to at least Swift 5.9. You can find this in your project settings under "Build Settings" -> "Swift Language Version".

Also, check for any deprecated APIs. Xcode often highlights these with warnings, but sometimes they can lead to build errors in newer versions.

MJ
Michael Jones

Re: Xcode Build Errors After Latest Update

Sarah's right about the Swift Language Version. I also found that cleaning the build folder (Product -> Clean Build Folder) sometimes helps resolve weird issues after an Xcode update.

If you're still stuck, try posting the full error log. Sometimes the preceding or succeeding errors give more clues.

JA
John Appleseed

Re: Xcode Build Errors After Latest Update

Thanks for the suggestions, Sarah and Michael!

I checked the Swift Language Version, and it was already set to Swift 5.9. I did try cleaning the build folder, which didn't seem to fix this specific error.

After digging a bit more, I found that the `async` keyword was indeed causing issues within a specific enum case. It seems like a conflict with how it was being used. I've managed to resolve it by refactoring that part of the code slightly.

The error message I posted was a bit misleading on its own. The real issue was related to how an `async` function was declared inside a context where it wasn't expected.

Here's a simplified representation of the problematic code (before fix):

1enum State { 2 case idle 3 case loading 4 case error(Error) 5 6 func fetchData() async throws -> [Item] { // Error here! 7 // ... implementation ... 8 } 9}

And the corrected version:

1enum State { 2 case idle 3 case loading 4 case error(Error) 5} 6 7extension State { 8 func fetchData() async throws -> [Item] { 9 // ... implementation ... 10 } 11}

By moving the `fetchData` function into an extension of `State`, the `async` keyword is now recognized correctly.

Thanks again for the help!

MJ
Michael Jones

Re: Xcode Build Errors After Latest Update

Ah, that makes perfect sense! Enum cases cannot contain methods directly in Swift. Moving it to an extension is the standard way to add methods to enums. Glad you figured it out!

SK
Sarah Kim

Re: Xcode Build Errors After Latest Update

Great detective work, John! That's a classic Swift nuance. Thanks for sharing the solution, it will definitely help others who run into this.

Have a solution or want to add to the discussion?

Reply to this thread