Swiftpack.co - danyaffff/RxOptionals as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by danyaffff.
danyaffff/RxOptionals 0.6-beta
Extensions that allow you to work with optionals
⭐️ 3
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/danyaffff/RxOptionals.git", from: "0.6-beta")

RxOptionals

Sometimes it happens that you need to bind to several optional binders or to an optional method (for example, when using weak). To do this, we can resort to large constructs with guard, if, weak capturing and others.

weak var someController: SomeController?

func bind() {
    guard let binder = someController?.someView.rx.someBinder else { /*...*/ }
    someObservable.bind(to: binder).disposed(by: bag)
}

The guard construction looks a bit messy and it would be great to remove it (and put inside called function).

weak var someController: SomeController?

func bind() {
    someObservable.bind(to: someController?.someView.rx.someBinder).disposed(by: bag)
}

It may seem that not so much changes and that the code is getting longer, but after a while you will realize that you saved a lot of time and space, and were able to write cleaner and more functional code (because optionals were created for this) ;)

Installation

CocoaPods

You could install package via CocoaPods:
Add this line to your Podfile:

pod 'RxOptionals', :git => 'https://github.com/danyaffff/RxOptionals'

Swift Package manager

You could install package via Swift Package manager:

  1. In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
  2. Paste the repository URL (https://github.com/danyaffff/RxOptionals) and click Next.
  3. For Rules, select Branch (and set main branch) and click Next.
  4. Add library to desired Target and click Finish.

GitHub

link
Stars: 3
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2 years ago

Tests added

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics