在iOS 14.5中,Apple更改为 @AppStorage
,以便可以在 observableObject
中正确使用它:
AppStorage属性包装器现在按预期运行时可以使用可观察到的对象,从而导致系统发射ObjectWillChange Publisher。 (65562845)
他们如何设法调用 observableboceboceboce
' ObjectWillChange 发布者从 @AppStorage
属性包装器中发行?他们在使用一些内部API吗?还是可以使用任何物业包装器来做到这一点?
我知道“魔术”的一部分是 dynamicproperty
协议。但是,仅此一项就不足以触发 objectWillChange
事件。我的猜测是,这是它们用于 @publed
的逻辑,据我所知,现在也不能真正成为“储备工程”。
有什么想法吗?
谢谢!
In iOS 14.5, Apple made a change to @AppStorage
so that it can be properly used within an ObservableObject
:
AppStorage property wrappers now work as expected when contained inside an ObservableObject, causing the system to emit the objectWillChange publisher. (65562845)
How do they manage to call the ObservableObject
's objectWillChange
publisher from within the @AppStorage
property wrapper? Are are they using some internal API? Or is it possible to do that with any property wrapper?
I know that one part of this "magic" is the DynamicProperty
protocol. But that alone is not enough to trigger an objectWillChange
event. My guess would be that it's the same logic they used for @Published
, which - as far as I know - also can't really be "reserve engineered" right now.
Any ideas?
Thanks!
发布评论
评论(1)
上次我检查时,有一个类扩展名,可以修改类,将调用添加到
objectwillchange.send()
of@publed
属性和我也假设@AppStorage
属性。我还记得如果您自己定义abocew> absockwillchange
自己会关闭这些机制。当我对其进行逆向工程时,代码对我来说看起来很脆弱,我确实认为自己只会调用objectwillsend
我自己更安全。Last time I checked there was a class extension that modifies the class to add the call to
objectWillChange.send()
in thewillSet
of@Published
properties and I assume also@AppStorage
properties. I remember also if you defineobjectWillChange
yourself then these mechanics get turned off. When I reverse engineered it, the code looked very fragile to me and I did think it maybe safer to just callobjectWillSend
myself.