Apple SDKs concurrency-readiness

I've been trying to use the Xcode 14 beta and the -warn-concurrency flag to make some of our library code concurrency-safe, and I've hit just… too many problems to manage.

A smattering of random data points:

  • Foundation types that I think should be Sendable, are not:
    • URL
    • Notification
    • ...
  • UIKit constants that should not be @MainActor, are:
    • UIApplication.willEnterForegroundNotification (it's just a string constant, and NotificationCenter itself is thread-safe)
  • UIKit types and methods that I think should not be @MainActor, are:
    • UIDevice, or at least I should be able to do UIDevice.current.systemVersion from any actor
  • Dispatch is completely concurrency-unaware — I kinda expected it to be unavailable, but instead it's available but doesn't understand swift concurrency
    • It'd at least be nice if DispatchQueue.main.[a]sync understood that its closure can be @MainActor (perhaps main could return a subclass of DispatchQueue with stronger guarantees?)
  • SwiftUI Button etc. callbacks aren't marked @MainActor, even though (AFAIK) they are — certainly it's always been legal to update @State vars from them — so it's not legal to call UIKit from them (eg. to present a UIViewController in response to a button press)

When can we expect Apple's SDKs to actually be usable with concurrency checking?

Looks like URL: Sendable was added in the Xcode 14 beta, though that difference doesn't show in the docs? Notification can't be Sendable because it references object, which may not be sendable

Apple SDKs concurrency-readiness
 
 
Q