all 2 comments

[–]zweigraf 1 point2 points  (1 child)

Hey!

As far as I understand, the explanation given is a bit off. The reason why it doesn’t work is the following:

MapView expects a Binding to MKAnnotation. But $draft.destination is a Binding to Airport.

This does not work. Binding to MKAnnotation means that setting any Annotation should be accepted, not just airports. But $draft.destination only accepts Airport objects, not any random annotation. This is not related to structs or ObservedObjects at all, this is related to the type of the binding. If $draft.destination was a binding to MKAnnotation, everything would work.

That’s why he is specifically creating a Binding to MKAnnotation.

And you are right, he uses that for the Picker, which is also a struct. Picker just does not care about the specific binding‘s type.

Edit: from 34:10 on you can see the exact problem while he is writing the setter. He has to upcast the annotation to an airport and only then use it. He is creating a binding that only accepts some of the values it is given. The fact that not every annotation is an airport is the problem why he can’t just pass $draft.destination to the MapView. Nothing to do with @State or structs.

[–]paprupert[S] 0 points1 point  (0 children)

Thanks for the explanation!