Learning SwiftUI
- component(call view below) is an
View (here means protocal View, not component)
struct, whit conform View
protocal
View
protocal just requires a body
which is some View
- add some state to view, need to add an
@State
in View; @State
has broken immutable property in struct
- Why view use struct instead class, cause struct is easy to destory and create, and high performanced compare with class
- when
@State
property is used to show, just use name; but when you need write change back to the property, need add $ before it. Eg: Text(name)
TextField("enter your name", text: $name)
, it will write name
, two-way binding
- The order of modifiers is matter: when you apply a modifier, it’s frame is determined. SwiftUI will not redraw the after modifier when you set a new frame modifier.
- View will re-render when
@State value
change.