[Swift] @State

고도·2021년 12월 2일
0

swift

목록 보기
2/2

오늘은 완벽한 대칭을 이루는 날짜이기에, 기념으로 적는다.
20211202 라는 대칭으로, 다음 대칭이 되는 날짜는
21100112 이기에, 이 날에는 내가 살아있지 않을 수도 있기 때문이다.

State

SwiftUI manages the storage of any property you declare as a state. When the state value changes, the view invalidates its appearance and recomputes the body. Use the state as the single source of truth for a given view.

SwiftUI에서는 변수에 대한 관리를 @State로 선언된 변수로 하는 것으로 판단된다.
@State 선언이 없으면, 뷰가 접근할 수 없는 것 같다.
정확한 의미를 알기 위해선 Property Wrapper에 대한 지식이 필요하다.

You should only access a state property from inside the view’s body, or from methods called by it.

State는 View's body 안에서만 접근하거나, methods를 통해야 한다.

profile
en attendant godot

0개의 댓글