How to use Observation to actually observe changes to a property

Well look at that, one of the original pitches had exactly what I need.

for await value in object.values(for: \.someProperty) {
     print(value)
}

Won't have time today to read the hundreds of posts that convinced the authors to arrive at the current implementation but I guess there were important reasons to do that. Hopefully something will be added in the future but it seems that currently the framework is not really that usable outside of SwiftUI.

Edit: If anyone else didn't follow the evolution and is curious why a general framework like Observation wouldn't have a way to actually observe properties, check out this thread. I am not smart enough to understand but I guess observing changes to properties that may run on different concurrency contexts is tricky (correct me if I'm wrong).

2 Likes