Why does a
SKScene
subclass elevate this error?The place is the Actor?
In the event you go up the inheritance hierarchy, you’d see that SKScene
in the end inherits from UIResponder
/NSResponder
, which is marked with a world actor – the MainActor
. See from its declaration right here.
@MainActor class UIResponder : NSObject
That is the place the actor is. Since your class additionally inherits from SKScene
, which in the end inherits from UIResponder
, your class additionally will get remoted to the worldwide actor.
why solely Process Teams?
It isn’t simply job teams. A extra minimal method to reproduce that is:
func foo(x: () async -> Void) {
}
func uploadCheckedImages() async {
foo {
let picture = photos[0]
}
}
Can I ease the compilers worries about it being handed as inout?
Sure, there are a variety of method, actually. A technique is to make a duplicate of the array:
func uploadCheckedImages() async {
let photos = self.photos // both right here...
await withTaskGroup(of: Void.self) { group in
// let photos = self.photos // or right here
// ...
}
}
Making photos
a let
fixed additionally works, if you are able to do that.
How is a race-condition doable with none writes?
I believe the compiler is simply form of being too restrictive right here. This will likely or will not be meant. It looks as if it is reporting an error for each l-value captured within the closure, even when it is not being written to. This error is meant to be triggered in conditions like this.
Your code is okay. In the event you add an id
perform and cross all of the l-value expressions into this perform, so that they now not appear to be l-values to the compiler, then the compiler is completely superb with it, although there’s completely no useful distinction.
// that is simply to indicate that your code is okay, not saying that it is best to repair your code like this
// @inline(__always) // you could possibly even do this
func id<T>(_ x: T) -> T { x }
await withTaskGroup(of: Void.self) { group in
for i in photos.indices {
let prev = i == 0 ? nil : id(photos[i - 1])
let curr = id(photos[i])