opacity | Apple Developer Documentation

A transition from transparent to opaque on insertion, and from opaque to transparent on removal.

Apple Developer Documentation
@kayleesdevlog Maybe Apple thinking your “oh no” list was too short and trying to find ways to put other things on it.

@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.

@cocoaphony well yeah, but wouldn’t that promise be kept inside the framework, so we don't have to worry about it? I'm sure there's other such cases (safe but can't be proven safe), that externally are just marked as safe… Right?

@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`

scale | Apple Developer Documentation

Returns a transition that scales the view.

Apple Developer Documentation

@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.

@cocoaphony I see, it’s the only instance I’ve encountered so I was a bit curious.