세상을 더 편리하게
article thumbnail
[iOS / SwiftUI] Combine - AnyCancellable
Swift/Apple Framework 2023. 5. 8. 04:59

AnyCancellable import Combine import SwiftUI struct CombineView: View { var vm = CombineViewModel() @State var anyCancellable = Set() @State var number = 0 var body: some View { VStack { Text("\(number)") .padding() Button(action: { vm.number.send(Int.random(in: 1...1000)) // # 수정됨 // print(vm.number) }, label: { Text("Button") }) Button(action: { anyCancellable.first?.cancel() }) { Text("Cancel..

article thumbnail
[iOS / SwiftUI] Combine - 맛보기
Swift/Apple Framework 2023. 4. 21. 02:29

잡담 면접관) 컴바인 아세요? 나) 콤바인 타봤습니다. 면접관 ) 아니... Combine.... 요새 콤바인이 모르는 사람도 많을 것이다. 하지만 iOS 개발자로서 Combine에 대해서 알아보자. SwiftUI에 대해서 필수이기에!! (써놓고 무슨 개그인지 나도 모르겠다.) Combine 언제나 그랬든 우선 WWDC 소개 영상을 보고오는 것을 추천한다. Combine이 나온 이유는 데이터의 동기화가 주 목적이다. 그래서 그런지 속속 RxSwift의 빈자리를 대체하고 있다. 예제로 살펴보기 import Combine import SwiftUI struct CombineView: View { var vm = CombineViewModel() @State var anyCancellable = Set() @..