WeakOwner 0.0.8

WeakOwner 0.0.8

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by ‘Beeth0ven --description=‘Mac Mini.



WeakOwner 0.0.8

  • By
  • Luo Jie




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.