Use weak references to pass to bindNext.
There are two ways to use RxBindNext.
final class RxBindNextExample {
let disposeBag = DisposeBag()
init() {
//First style
Observable.just("taewan")
.bindNext(weak: self, type(of: self).greetAgain)
.disposed(by: disposeBag)
//Second style
Observable.just("taewan")
.bindNext(weak: self, RxBindNextExample.greetAgain)
.disposed(by: disposeBag)
}
func greetAgain(person: String) {
print("Hello again, " + person + "!")
}
}
And drive is also supported.
Observable.just("taewan")
.asDriver(onErrorJustReturn: "-")
.drive(weak: self, type(of: self).greetAgain)
.disposed(by: disposeBag)
-
For iOS 8+ projects with CocoaPods:
pod 'RxBindNext', '~> 0.0.2'
-
For iOS 8+ projects with Carthage:
github "taewan0530/RxBindNext" ~> 0.0.2
http://blog.xebia.com/function-references-in-swift-and-retain-cycles/ https://medium.com/@gnod94/improvements-of-flatmap-function-in-rxswift-5d70add0fc88#.mjmtg1sp3
RxBindNext is under MIT license. See the LICENSE file for more info.