WeakOwner
A better way to deal function with weak reference.
At a Glance
-
Function without return value:
button.rx.tap .subscribe(onNext: weak(self) { me in me.showAlert() }) ...
is equivalent to:
button.rx.tap .subscribe(onNext: { [weak self] in guard let me = self else { return } me.showAlert() }) ...
-
Function with return value:
let searchResults = rxText .flatMapLatest(weak(self, default: .empty()) { me, text in me.searchGitHub(text) })
is equivalent to:
let searchResults = rxText .flatMapLatest { [weak self] text -> Observable<[Repository]> in guard let me = self else { return .empty() } return me.searchGitHub(text) }
Installation
-
For iOS 8+ projects with CocoaPods:
pod 'WeakOwner'
-
For iOS 8+ projects with Carthage:
github "beeth0ven/WeakOwner"
License
WeakOwner is under MIT license. See the LICENSE file for more info.