Hiding observable variables behind a read- and consume-only protocol

For the most part I don't believe the Observable macro attaches any stable public compile-time contracts. If a product engineer chose to depend on the Observable artifacts as a compile time contract I believe this would lead to brittle code… the macro engineer building Observable should have the freedom to refactor details that are not explicitly stable or public.

I believe the "least bad" solution for now is to enforce Observability as a runtime contract… not a compile time contract. This could be unit tests that set a value and then watch for the Observation callbacks.

I do believe there is discussion about shipping a new Observed type that could be used as a compile-time contract guarantee. I'm not completely sure if that was intended to "back deploy" to earlier versions of Swift. Potentially.

1 Like