
onAppear()func onAppear(perform action (() -> Void)? = nil) -> some View
func onAppear()
func onAppear(perform: {
// action
})
onDisappear()func onDisappear(perform action: (() -> Void)? = nil) -> some View
onAppear()과 유사하게 사용onChange()func onChange<V> {
of value: V,
perform action: @escaping (V) -> Void
} -> some View where V : Equatable
특정 값이 변할 때 action 수행한다.
onChange 메서드 파라미터
onChange를 사용해 Environment key 또는 Binding과 같은 값 변경의 결과로 side-effect를 트리거할 수 있다.
onChange는 메인 스레드에서 호출된다.
newValue는 closure로 전달된다.
https://developer.apple.com/documentation/swiftui/view/onappear(perform:)
https://developer.apple.com/documentation/swiftui/view/ondisappear(perform:)
https://developer.apple.com/documentation/swiftui/view/onchange(of:perform:)