Ray Wenderlich/Combine
-
Ch5. Combining OperatorsRay Wenderlich/Combine 2021. 2. 12. 01:51
Prepending prepend(Output...) let publisher = [3, 4].publisher publisher .prepend(1, 2) .sink(receiveValue: { print($0) }) .store(in: &subscriptions) 1 2 3 4 prepend(Sequence) Sequence프로토콜을 따르는 타입을 전달받을 수 있음 let publisher = [5, 6, 7].publisher publisher .prepend([3, 4]) .prepend(Set(1...2)) .prepend(stride(from: 6, to: 11, by: 2)) .sink(receiveValue: { print($0) }) .store(in: &subscriptions) 6 8..
-
Ch4. Filtering OperatorsRay Wenderlich/Combine 2021. 2. 12. 01:44
filter(_:) let numbers = (1...10).publisher numbers .filter { $0.isMultiple(of: 3) } .sink(receiveValue: { n in print("\(n) is a multiple of 3!") }) .store(in: &subscriptions) 3 is a multiple of 3! 6 is a multiple of 3! 9 is a multiple of 3! removeDuplicates() let words = "hey hey there! want to listen to mister mister ?" .components(separatedBy: " ") .publisher words .removeDuplicates() .sink(r..
-
Ch3. Transforming OperatorsRay Wenderlich/Combine 2021. 1. 27. 20:26
collect() ["A", "B", "C", "D", "E"].publisher .collect() .sink(receiveCompletion: { print($0) }, receiveValue: { print($0) }) .store(in: &subscriptions) // collect에 parameter전달하여 메모리 과다사용 방지 ["A", "B", "C", "D", "E"].publisher.collect(3) .sink(receiveCompletion: { print($0) }, receiveValue: { print($0) }) .store(in: &subscriptions) ["A", "B", "C", "D", "E"] finished ["A", "B", "C"] ["D", "E"] fi..
-
Ch2. Publishers & SubscribersRay Wenderlich/Combine 2021. 1. 27. 20:23
Hello Publisher let myNotification = Notification.Name("MyNotification") let center = NotificationCenter.default let observer = center.addObserver(forName: myNotification, object: nil, queue: nil) { (notification) in print("Notification received!") } center.post(name: myNotification, object: nil) center.removeObserver(observer) Notification received! Hello Subscriber let myNotification = Notific..
-
Ch1. Hello, Combine!Ray Wenderlich/Combine 2021. 1. 27. 20:22
애플이 말했다. ‘The Combine framework provides a declarative approach for how your app processes events. Rather than potentially implementing multiple delegate callbacks or completion handler closures, you can create a single processing chain for a given event source. Each part of the chain is a Combine operator that performs a distinct action on the elements received from the previous step’'컴바인은 여러분의..