Published (1) 썸네일형 리스트형 SwiftUI] StateObject, Published, ObservableObject https://www.hackingwithswift.com/books/ios-swiftui/sharing-swiftui-state-with-stateobject swiftui 에서 struct 인스턴스 변수는 간단한 @State 로 (내부 프로퍼티의) 변경을 감지하여 UI에 반영할 수 있다. 하지만 class 인스턴스 변수는 @State 를 붙여도 내부 프로퍼티의 변경을 감지하지 못한다. class 의 내부 프로퍼티의 변경을 감지하도록 하는 방법은 다음과 같다. 1. 외부에서 변경을 감지하려는 클래스의 프로퍼티에 @Published 를 붙여준다. class User { @Published var name: String = "Micky" @Published var age: Int = 10 } 2. view.. 이전 1 다음