Integrating RxSwift Into Your Brain and Code Base

Replacing IBActions

browseForPeersButton.rx.tap
.bind(onNext: { [weak self] in self?.browseForPeers() })
.disposed(by: disposeBag)

Replacing Delegates: Removing App Specific Protocols

var didCreateChatRoom: Observable<(displayName: String, serviceType: String)> {
return _didCreateChatRoom.asObservable()
}
private let _didCreateChatRoom = PublishSubject<(displayName: String, serviceType: String)>()

Replacing Delegates: Wrapping iOS provided protocols

imagePicker.rx.didCancel
.bind(onNext: { [weak self] in
self?.imagePickerControllerDidCancel()
})
.disposed(by: disposeBag)
imagePicker.rx.didFinishPickingMediaWithInfo
.bind(onNext: { [weak self] info in
self?.didFinishPickingMediaWithInfo(info)
})
.disposed(by: disposeBag)

Replacing Notification Observers

Fixing a photo capture bug

extension Reactive where Base: PHPhotoLibrary {
static var requestAuthorization: Observable<PHAuthorizationStatus> {
return Observable.create { observer in
Base.requestAuthorization { status in
observer.onNext(status)
observer.onCompleted()
}
return Disposables.create()
}
}
}

Replacing KVO

Interlude

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniel Tartaglia

Daniel Tartaglia

I started programming as a hobby in the late ’70s and professionally in the late ’90s. I’ve been writing iOS apps since 2010 and using RxSwift since 2015.