If you're using RxSwift, you've probably encountered the following code more than a few times.
class MyObject: Whatever {
let disposeBag = DisposeBag()
...
}
You're actually not the only one; it has been typed many, many times.
Instead of adding a new property to every object, use this library to add it for you, to any subclass of NSObject
.
thing
.bindTo(otherThing)
.addDisposableTo(rx_disposeBag)
Sweet.
It'll work just like a property: when the instance is deinit'd, the DisposeBag
gets disposed. It's also a read/write property, so you can use your own, too.
This works with RxSwift version 2, which is still prerelease, so you've gotta be fancy with your podfile.
pod 'RxSwift', '~> 2.0.0-beta'
pod 'NSObject+Rx'
And that'll be ๐
MIT obvs.