so i was fiddling around with recreating the State<T> and Binding<T> property wrappers, and i'm really confused that they're both declared structs, presumably with “value” semantics like everything else in the language, yet the Binding<T> should be able to mutate the State<T> by reference, and i can’t seem to construct the closures to make the Binding<T> out of.
does State<T> then actually wrap a class type, and pass (weak?) self to the Binding<T>’s initializer? is it a copy on write type, that just lets the Binding<T> instance bypass the copy?
i don't think thats how it works,, you can't use it without an init(initialValue:) initializer:
struct S
{
@State
var model:Int = 0
}
51:9: error: initializing property 'model' with wrapper 'State' that lacks an 'init(initialValue:)' initializer
var model:Int = 0
^ ~
50:5: note: initialize the property wrapper type directly with '(...') on the attribute
@State
^
3:8: note: generic struct 'State' declared here
struct State<Value> {
Could it be that State relies on framework-wide shared storage, esp. since it has update function? It wouldn't too foreign of a concept as Apple has done it at many places before.
I'd be weird if State struct itself is persistent considering that it is init every time body is called (which is every time State registers change). It could be that ViewBuilder is tracking its hierarchy somehow.
It was stated a couple of times during the talks that the @State properties had their storage managed by the layout system. It would therefore make sense that some sort of pointer would be passed in to the View initializer for those properties.
Yup, they are quite good. Even without the videos, Apple quite likes the notion of I'll manage that for you, like IBOutlet, NSManagedObject, so it's not even hard to guess.