Twitter | Search | |
Drew McCormack Jan 29
SwiftUI Q: how does a Published property determine what ObservableObject it belongs to, so it can fire the publisher? Does the object use mirror on init to register with the properties?
Reply Retweet Like
Ole Begemann
Some info/conjecture in these threads: Short answer: IIUC the default implementation for objectWillChange uses runtime introspection to find all Published properties and injects the publisher.
The synthesized objectWillChange creates an ObservableObjectPublisher once and installs it into all the @Published properties using runtime introspection. When you access objectWillChange, it will...
Reply Retweet Like More
Ole Begemann Jan 30
Replying to @drewmccormack
There’s also an unofficial feature that allows a property wrapper to access the “enclosing self”, i.e. the owning object. I don’t know if Published uses this, though.
Reply Retweet Like
Drew McCormack Jan 30
Replying to @olebegemann
Thanks. Very useful.
Reply Retweet Like