Coder Social home page Coder Social logo

rxoptionals's Introduction

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.

rxoptionals's People

Contributors

danyaffff avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.