세상을 더 편리하게
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..