So why would `AnyTransition.opacity` be marked as `unsafe`?
https://developer.apple.com/documentation/swiftui/anytransition/opacity
So why would `AnyTransition.opacity` be marked as `unsafe`?
https://developer.apple.com/documentation/swiftui/anytransition/opacity
@kayleesdevlog This indicates that `opacity` is promised by the author (Apple) to be safe to call from any context (i.e. any thread), even though the compiler can't prove it. The "unsafe" here means that you must trust the author to follow the rules rather than the compiler enforcing the rules.
For details on nonisolated(unsafe), see the SE proposal: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
This annotation opts out of static checking, but not dynamic (runtime) checking, so if there are mistakes, it may crash.
@kayleesdevlog In this case, I am pretty sure the problem is that Opacity is itself an AnyTransition, and AnyTransition is not Sendable. But I'm betting the underlying transition *is* Sendable, and Apple would like to expose that. This would be the best way to express that promise without creating an extra protocol indirection (which would have a runtime cost).
Even with that, you'd probably still need the `unsafe` marking, since *this* type isn't Sendable. I don't think that's hideable.
@cocoaphony if that was the case, wouldn't all other members need to be unsafe as well? `opacity` seems to be the only one, e.g.:
https://developer.apple.com/documentation/swiftui/anytransition/scale
is fine while still being an `AnyTransition` static member of `AnyTransition`
@kayleesdevlog `scale` isn't nonisolated. (it's also a computed property, not a `let` property, but it's not nonisolated at all.)
I would expect that there are internal reasons that Apple made opacity nonisolated, and they could have wrapped it in a getter to be like the others. But there is likely history there, or a performance tweak.
But the key is that "make sure `unsafe` does not appear in the interface" is not a particularly major design goal. It shows up a bit.