Learning SwiftUI

Learning SwiftUI

Created
Jan 4, 2024 01:51 PM
Date
Category
Tags
SwiftUI
  1. component(call view below) is an View (here means protocal View, not component) struct, whit conform View protocal
  1. View protocal just requires a body which is some View
  1. add some state to view, need to add an @State in View; @State has broken immutable property in struct
  1. Why view use struct instead class, cause struct is easy to destory and create, and high performanced compare with class
  1. 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:
    1. Text(name)
    2. TextField("enter your name", text: $name) , it will write name, two-way binding
  1. 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.
  1. View will re-render when @State value change.