-1

Xcode keeps throwing a complier error that it doesn't comply with Swift 6 Which isn't obv out yet. It only started when I downloaded 13.3 Xcode.

The error reads:

Expression requiring global actor 'MainActor' cannot appear in default-value expression of property '_api'; this is an error in Swift 6

my code is doing an state object call like so:

    @StateObject var api = RecipeAPI()

I have debugged and closed and reopened everything but nothing changes. Reported it to apple too.

Best,

Imran

Imran
  • 13
  • 4
  • This should be a warning. Are you sure you don't have `-Werror` (turning warnings into errors) turned on? – Rob Napier Mar 21 '22 at 18:20
  • I have no idea what that is and how to turn it off. It's a yellow warning, so my bad for the incorrect name. – Imran Mar 21 '22 at 18:41

1 Answers1

1

That's a warning in Swift 5. In Swift 6, it'll be an error. It's suggesting that you fix it now, but in the future it'll break the build. You're requiring that everything (including the init be run on the MainActor, but this assignment isn't promised to run on the MainActor itself (possibly because the type it's part of isn't also marked @MainActor). You may find a lot of these in 5.6 that are extremely difficult to fix. They're still tuning the warnings. (So when you start to formulate your next question "how do I eliminate all Swift concurrency warnings when dealing with SwiftUI and Foundation," the answer may be "you can't, or at least not in any easy way." It depends on the exact problem.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610