I'm in Xcode 16 beta 5. I've got this code:
@objc class func fetch(product: StoreListProduct, completion: @escaping @Sendable (AppStoreProduct?) -> Void) {
Task {
let result = await AppStoreProduct.product(forListProduct: product)
DispatchQueue.main.async {
completion(result)
}
}
}
For context:
- I am moving to StoreKit 2 in a largely Objective-C codebase.
StoreListProduct
is an Objective-C class that wraps anNSDictionary
built from json fetched from my server describing a product in my store, and exposes various keys in that dictionary as typed properties for convenience.AppStoreProduct
is a Swift class wrapping the StoreKit 2Product
class and exposing various parts of it to Objective-C. It's marked asSendable
.AppStoreProduct.product(forListProduct:)
is a Swift method that ultimately just wraps theProduct.products
method in StoreKit 2.
I'm getting this warning on the Task {
line:
Task-isolated value of type '() async -> ()' passed as a strongly transferred parameter; later accesses could race; this is an error in the Swift 6 language mode
My best interpretation of this is that the closure being passed to the Task
is considered to be task-isolated because it's capturing the non-Sendable StoreListProduct
, so the closure can't be transferred across the isolation boundary. But I'm a little confused by the warning's reference to "later accesses". The closure is defined locally once and not stored.
In practice, I believe this is safe because StoreListProduct
is immutable.
What's the best way to mark this as (or make it) safe?