This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = PublishSubject<String>() | |
subject.onNext("Is anyone listening?") | |
let subcription1 = subject.subscribe { event in | |
print("1) \(event)") | |
} | |
let subcription2 = subject.subscribe { event in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = PassthroughSubject<String, Error>() | |
subject.send("Is anyone listening?") | |
let subcription1 = subject.sink(receiveCompletion: { | |
print("1) \($0)") | |
}, receiveValue: { | |
print("1) \($0)") | |
}) | |
let subscription2 = subject.sink(receiveCompletion: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = BehaviorSubject<String>.init(value: "Init Value") | |
subject.onNext("Is anyone listening?") | |
let subcription1 = subject.subscribe { event in | |
print("1) \(event)") | |
} | |
let subcription2 = subject.subscribe { event in | |
print("2) \(event)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = CurrentValueSubject<String, Error>.init("Init Value") | |
subject.send("Is anyone listening?") | |
let subcription1 = subject.sink(receiveCompletion: { | |
print("1) \($0)") | |
}, receiveValue: { | |
print("1) \($0)") | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1,2,3,4,5].toObservable() | |
.subscribeOn(MainScheduler.instance) | |
.doOnNext { | |
UIApplication.sharedApplication().networkActivityIndicatorVisible = true | |
} | |
.observeOn(backgroundScheduler) | |
.flatMapLatest { | |
HTTPBinDefaultAPI.sharedAPI.get($0) | |
} | |
.observeOn(MainScheduler.instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let jsonPublisher = MyJSONLoaderPublisher() // Some publisher. | |
let labelUpdater = MyLabelUpdateSubscriber() // Some subscriber that updates UI | |
jsonPublisher | |
.subscribe(on: backgroundQueue) | |
.receiveOn(on: RunLoop.main) | |
.subscribe(labelUpdater) | |
// 출처 : https://developer.apple.com/documentation/combine/publishers/prefixuntiloutput/3210286-receive?changes=_4_2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let backgroundScheduler = SerialDispatchQueueScheduler(qos: .background) | |
Observable.just(1) | |
.map { _ in | |
print(Thread.isMainThread) // false | |
} | |
.subscribeOn(backgroundScheduler) | |
.map { _ in | |
print(Thread.isMainThread) // false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let backgroundQueue = DispatchQueue.global(qos: .background) | |
Publishers.Just(1) | |
.map { _ in | |
print(Thread.isMainThread) // true | |
} | |
.subscribe(on: backgroundQueue) | |
.map { _ in | |
print(Thread.isMainThread) // false | |
}.sink { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Publishers.Just(1) | |
.subscribe(on: backgroundQueue) | |
.map { _ in | |
print(Thread.isMainThread) // false | |
} | |
.map { _ in | |
print(Thread.isMainThread) // false | |
}.sink { | |
print(Thread.isMainThread) // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let stream = Publishers.Just("is Alive?") | |
.delay(for: .seconds(5), scheduler: RunLoop.main) | |
.sink(receiveCompletion: { (completion) in | |
switch completion { | |
case .finished: print("finished") | |
case .failure(let error): print(error) | |
} | |
}, receiveValue: { | |
print($0) | |
}) |
OlderNewer