Latest 1.2.3
Homepage https://github.com/tokijh/RxSwiftExtensions
License MIT
Platforms ios 8.0
Dependencies RxSwift, RxCocoa, RxOptional, RxViewController
Frameworks Foundation
Authors

Swift 4.2
Version
License
Platform

Frequently used extensions in RxSwift


Dear those who love RxSwift

This library based on questions from KakaoTalk open chat room.
Join us if you have some questions about RxSwift or you are interested. We always welcome 😀
However, this chat room us operating in South Korea. Therefore, you will need speaking Korean 🇰🇷

이 라이브러리는 카카오톡 오픈 채팅방에서 올라온 질문을 바탕으로 만들어졌습니다.
RxSwift에 관련하여 질문이 있거나 관심이 있다면 언제든지 가벼운 마음으로 참여하세요 😀
이 방은 한국에서 운영되는 것이라 한국어를 필요로 할 수 있습니다… (이거 읽으실 정도면 문제없을 겁니다 😂)

このライブラリーはカカオトークオープンチャットルームに投稿された質問を基に作られました。
RxSwiftについて質問や興味があれば、いつでも気軽に参加してください 😀
このルームは韓国で営業されているものなので韓国語を必要とします 🇰🇷


Functions

Swift

KVO

– [x] [`observe(keyPath: KeyPath)`](#observekeypath-keypath—observablevalue)
– [x] [`observeWeakly(keyPath: KeyPath)`](#observeweaklykeypath-keypath—observablevalue)
– [x] [`SectionDataType`](#sectiondatatype)

UIKit

UIView

– [x] [`UIView.rx.bounds`](#uiviewrxbounds)
– [x] [`UIView.rx.center`](#uiviewrxcenter)

  • UILabel

    – [x] [`UILabel.rx.textColor`](#uilabelrxtextcolor)

  • UITextView

    – [x] [`UITextView.rx.textColor`](#uitextviewrxtextcolor)

  • UIScrollView

    – [x] [`UIScrollView.rx.contentSize`](#uiscrollviewrxcontentsize)
    – [x] [`UIScrollView.rx.scrollableVertical`](#uiscrollviewrxscrollablevertical)
    – [x] [`UIScrollView.rx.scrollableHorizontal`](#uiscrollviewrxscrollablehorizontal)

  • UITableView

    – [x] [`register(cell: UITableViewCell.self)`](#uitableviewregistercell-uitableviewcellself)
    – [x] [`register(nibCell: UITableViewCell.self)`](#uitableviewregisternibcell-uitableviewcellself)
    – [x] [`register(cell: UITableViewHeaderFooterView.self)`](#uitableviewregistercell-uitableviewheaderfooterviewself)
    – [x] [`register(nibCell: UITableViewHeaderFooterView.self)`](#uitableviewregisternibcell-uitableviewheaderfooterviewself)
    – [x] [`dequeue(UITableViewCell.self)`](#uitableviewdequeueuitableviewcellself)
    – [x] [`dequeue(UITableViewCell.self, indexPath: IndexPath)`](#uitableviewdequeueuitableviewcellself-indexpath-indexpath)
    – [x] [`dequeue(UITableViewHeaderFooterView.self)`](#uitableviewdequeueuitableviewheaderfooterviewself)
    – [x] [`rx.items(Cell.self)`](#uitableviewrxitemscellself)

    UITableViewCell

    – [x] [`UITableViewCell.Identifier`](#uitableviewcellidentifier)

    • UITableViewHeaderFooterView

      – [x] [`UITableViewHeaderFooterView.Identifier`](#uitableviewheaderfooterviewidentifier)

  • UICollectionView

    – [x] [`register(cell: UICollectionViewCell.self)`](#uicollectionviewregistercell-uicollectionviewcellself)
    – [x] [`register(nibCell: UICollectionViewCell.self)`](#uicollectionviewregisternibcell-uicollectionviewcellself)
    – [x] [`register(cell: UICollectionReusableView.self, forSupplementaryViewOfKind kind: String)`](#uicollectionviewregistercell-uicollectionreusableviewself-forsupplementaryviewofkind-supplementaryviewofkind)
    – [x] [`register(nibCell: UICollectionReusableView.self, forSupplementaryViewOfKind kind: String)`](#uicollectionviewregistercell-uicollectionreusableviewself-forsupplementaryviewofkind-supplementaryviewofkind)
    – [x] [`dequeue(UICollectionViewCell.self, for indexPath: IndexPath)`](#uicollectionviewdequeueuicollectionviewcellself-for-indexpath)
    – [x] [`dequeue(UICollectionViewCell.self, ofKind kind: String, for indexPath: IndexPath)`](#uicollectionviewdequeueuicollectionreusableviewself-ofkind-supplementaryviewofkind-for-indexpath)
    – [x] [`rx.items(Cell.self)`](#uicollectionviewrxitemscellself)

    UICollectionReusableView

    – [x] [`UICollectionReusableView.Identifier`](#uicollectionreusableviewidentifier)

  • UIViewController

    – [x] [`UIViewController.rx.viewDidLoad`](#uiviewcontrollerrxviewdidload)
    – [x] [`UIViewController.rx.viewWillAppear`](#uiviewcontrollerrxviewwillappear)
    – [x] [`UIViewController.rx.viewDidAppear`](#uiviewcontrollerrxviewdidappear)
    – [x] [`UIViewController.rx.viewWillDisappear`](#uiviewcontrollerrxviewwilldisappear)
    – [x] [`UIViewController.rx.viewDidDisappear`](#uiviewcontrollerrxviewdiddisappear)
    – [x] [`UIViewController.rx.viewWillLayoutSubviews`](#uiviewcontrollerrxviewwilllayoutsubviews)
    – [x] [`UIViewController.rx.viewDidLayoutSubviews`](#uiviewcontrollerrxviewdidlayoutsubviews)
    – [x] [`UIViewController.rx.willMove(toParentViewController: UIViewController)`](#uiviewcontrollerrxwillmovetoparentviewcontroller-uiviewcontroller)
    – [x] [`UIViewController.rx.didMove(toParentViewController: UIViewController)`](#uiviewcontrollerrxdidmovetoparentviewcontroller-uiviewcontroller)
    – [x] [`UIViewController.rx.didReceiveMemoryWarning`](#uiviewcontrollerrxdidreceivememorywarning)
    – [x] [`UIViewController.rx.isVisible`](#uiviewcontrollerrxisvisible)
    – [x] [`UIViewController.rx.isDismissing`](#uiviewcontrollerrxisdismissing)

    RxSwift
  • ObservableType

    – [x] [`withLatestFrom(…)`](#observabletype-withlatestfrom)
    – [x] [`withLatestFromAndSelf(…)`](#observabletype-withlatestfromandself)
    – [x] [`bind(to [ObserverType])`](#observabletype-bindto-observertype)
    – [x] [`bind(to Optional)`](#observabletype-bindto-optionalobservertype)

    RxCocoa
  • SharedSequenceConvertibleType

    – [x] [`withLatestFrom(…)`](#sharedsequenceconvertibletype-withlatestfrom)
    – [x] [`withLatestFromAndSelf(…)`](#sharedsequenceconvertibletype-withlatestfromandself)

Functions Detail

Swift

KVO

observe(keyPath: KeyPath) -> Observable

Observe [KVO](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html) by keyPath

[KVO](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html) is an Objective-C mechanism. That means that it wasn’t built with type safety in mind. This project tries to solve some of the problems.

“`
UIView()
.observe(.bounds, , options: [.initial, .new], retainSelf: true)
.subscribe({ print($0) })
“`

- <details><summary>observeWeakly(keyPath: KeyPath) -> Observable<Value?></summary>

  Observe [KVO](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html) by keyPath

  `rx.observeWeakly` has somewhat slower than `rx.observe` because it has to handle object deallocation in case of weak references.

  ```
  UIView()
    .observeWeakly(.bounds, , options: [.initial, .new], retainSelf: true)
    .subscribe({ print($0) })
  ```
  </details>
</details>
  • SectionDataType

    Define Section Data easily in tableView or collectionView

    Define follow

    “`
    enum TestSectionData {
    case section1
    case section2([Value])
    }

    extension TestSectionData: SectionDataType {

    typealias Item = Value

    var items: [TestSectionData.Value] {
    switch self {
    case .section1: return [.string(“Section 1”)]
    case let .section2(value): return value
    }
    }

    enum Value {
    case string(String)
    case int(Int)
    }
    }
    “`

    You can use it follow

    “`
    let section = sections[indexPath.section].items[indexPath.row]

    switch section {
    case let .int(value):
    cell.set(value)
    return cell
    case let .string(value):
    cell.set(value)
    return cell
    }
    “`

UIKit

UIView

UIView.rx.bounds

Observe bounds in UIView

“`
UIView().rx.bounds.subscribe({ print($0) })
“`

- <details><summary>UIView.rx.center</summary>

    Observe center in UIView

    ```
    UIView().rx.center.subscribe({ print($0) })
    ```
  </details>
</details>
  • UILabel

    UILabel.rx.textColor

    Binder textColor in UILabel

    “`
    Observable.just(UIColor.white).bind(to: UILabel().rx.textColor)
    “`

  • UITextView

    UITextView.rx.textColor

    Binder textColor in UITextView

    “`
    Observable.just(UIColor.white).bind(to: UITextView().rx.textColor)
    “`

  • UIScrollView

    UIScrollView.rx.contentSize

    Observe contentSize in UIScrollView

    “`
    UIScrollView().rx.contentSize.subscribe({ print($0) })
    “`

    • UIScrollView.rx.scrollableVertical

      Observe scrollable of vertical (`bounds.height

    • UIScrollView.rx.scrollableHorizontal

      Observe scrollable of horizontal (`bounds.width

  • UITableView

    UITableView.register(cell: UITableViewCell.self)

    Register UITableViewCell easily

    Following sample will be register with “Cell” (`UITableViewCell.Identifier`).

    “`
    UITableView().register(cell: Cell.self)
    “`

    Also you can define Identifier like follow

    “`
    UITableView().register(cell: Cell.self, forCellReuseIdentifier: “CustomIdentifier”)
    “`

    • UITableView.register(nibCell: UITableViewCell.self)

      Register UITableViewCell using NIB easily

      Following sample will be register with “Cell” (`UITableViewCell.Identifier`).

      “`
      UITableView().register(nibCell: Cell.self)
      “`

      Also you can define Identifier like follow

      “`
      UITableView().register(nibCell: Cell.self, forCellReuseIdentifier: “CustomIdentifier”)
      “`

    • UITableView.register(cell: UITableViewHeaderFooterView.self)

      Register UITableViewHeaderFooterView easily

      FolloFollowing sample will be register with “Cell” (`UITableViewHeaderFooterView.Identifier`).

      “`
      UITableView().register(cell: Cell.self)
      “`

      Also you can define Identifier like follow

      “`
      UITableView().register(cell: Cell.self, forCellReuseIdentifier: “CustomIdentifier”)
      “`

    • UITableView.register(cell: UITableViewHeaderFooterView.self)

      Register UITableViewCell using NIB easily

      FolloFollowing sample will be register with “Cell” (`UITableViewHeaderFooterView.Identifier`).

      “`
      UITableView().register(cell: Cell.self)
      “`

      Also you can define Identifier like follow

      “`
      UITableView().register(cell: Cell.self, forCellReuseIdentifier: “CustomIdentifier”)
      “`

    • UITableView.dequeue(UITableViewCell.self)

      Dequeue UICollectionViewCell easily

      Following sample will be dequeue with “Cell” (`UICollectionReusableView.Identifier`).

      “`
      let cell: Cell? = UITableView().dequeue(Cell.self)
      “`

    • UITableView.dequeue(UITableViewCell.self, indexPath: IndexPath)

      Dequeue UICollectionViewCell easily

      Following sample will be dequeue with “Cell” (`UICollectionReusableView.Identifier`).

      “`
      let cell: Cell? = UITableView().dequeue(Cell.self, indexPath: IndexPath)
      “`

    • UITableView.dequeue(UITableViewHeaderFooterView.self)

      Dequeue UITableViewHeaderFooterView easily

      “`
      let cell: Cell? = UITableView().dequeue(Cell.self)
      “`

    • UITableView.rx.items(Cell.self)

      Bind items by rx

      “`
      Observable.just([“0”, “1”, “2”, “3”])
      .bind(to: tableView.rx.items(cell: Cell.self)) { row, item, cell in

      }
      “`

    • UITableViewCell
    • UITableViewCell.Identifier

      Define Identifier by class name

      “`
      class MyCell: UITableViewCell {

      }

      MyCell.Identifier == “MyCell”
      “`

    • UITableViewHeaderFooterView
    • UITableViewHeaderFooterView.Identifier

      Define Identifier by class name

      “`
      class MyCell: UITableViewHeaderFooterView {

      }

      MyCell.Identifier == “MyCell”
      “`

    • UICollectionView
    • UICollectionView.register(cell: UICollectionViewCell.self)

      Register UICollectionViewCell easily

      Following sample will be register with “Cell” (`UICollectionReusableView.Identifier`).

      “`
      UICollectionView().register(cell: Cell.self)
      “`

      Also you can define Identifier like follow

      “`
      UICollectionView().register(cell: Cell.self, forCellWithReuseIdentifier: “CustomIdentifier”)
      “`

    • UICollectionView.register(nibCell: UICollectionViewCell.self)

      Register UICollectionViewCell using NIB easily

      Following sample will be register with “Cell” (`UICollectionReusableView.Identifier`).

      “`
      UICollectionView().register(nibCell: Cell.self)
      “`

      Also you can define Identifier like follow

      “`
      UICollectionView().register(nibCell: Cell.self, forCellWithReuseIdentifier: “CustomIdentifier”)
      “`

    • UICollectionView.register(cell: UICollectionReusableView.self, forSupplementaryViewOfKind: SupplementaryViewOfKind)

      Register UICollectionReusableView for SupplementaryViewOfKind

      “`
      UICollectionView().register(cell: Cell.self, forSupplementaryViewOfKind: .header)

      UICollectionView().register(nibCell: Cell.self, forSupplementaryViewOfKind: .footer)
      “`

    • UICollectionView.dequeue(UICollectionViewCell.self, for: IndexPath)

      Dequeue UICollectionViewCell easily

      Following sample will be dequeue with “Cell” (`UICollectionReusableView.Identifier`).

      “`
      let cell: Cell? = UICollectionView.dequeue(Cell.self, for: IndexPath)
      “`

    • UICollectionView.dequeue(UICollectionReusableView.self, ofKind: SupplementaryViewOfKind, for: IndexPath)

      DeDequeue UICollectionReusableView for SupplementaryViewOfKind easily

      “`
      let cell: Cell? = UICollectionView.dequeue(Cell.self, ofKind: .header, for: IndexPath)
      “`

    • UICollectionView.rx.items(Cell.self)

      Bind items by rx

      “`
      Observable.just([“0”, “1”, “2”, “3”])
      .bind(to: collectionView.rx.items(cell: Cell.self)) { row, item, cell in

      }
      “`

    • UICollectionReusableView
    • UICollectionReusableView.Identifier

      Define Identifier by class name

      “`
      class MyCell: UICollectionReusableView {

      }

      MyCell.Identifier == “MyCell”
      “`

    • UIViewController
  • UIViewController.rx.viewDidLoad

    Observe when called `viewDidLoad` in UIViewController

    “`
    UIViewController().rx.viewDidLoad.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewWillAppear

    Observe when called `viewWillAppear` in UIViewController

    “`
    UIViewController().rx.viewWillAppear.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewDidAppear

    Observe when called `viewDidAppear` in UIViewController

    “`
    UIViewController().rx.viewDidAppear.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewWillDisappear

    Observe when called `viewWillDisappear` in UIViewController

    “`
    UIViewController().rx.viewWillDisappear.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewDidDisappear

    Observe when called `viewDidDisappear` in UIViewController

    “`
    UIViewController().rx.viewDidDisappear.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewWillLayoutSubviews

    Observe when called `viewWillLayoutSubviews` in UIViewController

    “`
    UIViewController().rx.viewWillLayoutSubviews.subscribe({ print($0) })
    “`

  • UIViewController.rx.viewDidLayoutSubviews

    Observe when called `viewDidLayoutSubviews` in UIViewController

    “`
    UIViewController().rx.viewDidLayoutSubviews.subscribe({ print($0) })
    “`

  • UIViewController.rx.willMove(toParentViewController: UIViewController)

    Observe when called `willMove(toParentViewController: UIViewController)` in UIViewController

    “`
    UIViewController().rx.willMove(toParentViewController: parentViewController).subscribe({ print($0) })
    “`

  • UIViewController.rx.didMove(toParentViewController: UIViewController)

    Observe when called `didMove(toParentViewController: UIViewController)` in UIViewController

    “`
    UIViewController().rx.didMove(toParentViewController: parentViewController).subscribe({ print($0) })
    “`

  • UIViewController.rx.didReceiveMemoryWarning

    Observe when called `didReceiveMemoryWarning` in UIViewController

    “`
    UIViewController().rx.didReceiveMemoryWarning.subscribe({ print($0) })
    “`

  • UIViewController.rx.isVisible

    Triggered when the ViewController appearance state changes (true if the View is being displayed, false otherwise)

    “`
    UIViewController().rx.isVisible.subscribe({ print($0) })
    “`

  • UIViewController.rx.isDismissing

    Triggered when the ViewController is being dismissed

    “`
    UIViewController().rx.isDismissing.subscribe({ print($0) })
    “`

    RxSwift
  • ObservableType

    withLatestFrom

    Extend withLatestFrom for support multi parameters

    “`
    let a = Observable.just(“A”)
    let b = Observable.just(“B”)
    let c = Observable.just(“C”)

    Observable().withLatestFrom(a, b, c)
    .subscribe(onNext: { (a, b, c) in

    })
    “`

    • withLatestFromAndSelf

      Extend withLatestFromAndSelf for combining parameters with self

      “`
      let a = Observable.just(“A”)
      let b = Observable.just(“B”)
      let c = Observable.just(“C”)

      Observable().withLatestFromAndSelf(a, b, c)
      .subscribe(onNext: { (a, b, c) in

      })
      “`

    • bind(to [ObserverType?]?)

      Can bind multiple ObserverType in one line

      “`
      let publisher = PublishSubject()

      let observers: [PublishSubject] = […]

      let disposable = publisher.bind(to: observers)
      “`

    • bind(to ObserverType?)

      Can bind optional type
      if ovserver is nil, it will ignore subscribe

      “`
      let publisher = PublishSubject()

      let observer: PublishSubject? = nil

      let disposable = publisher.bind(to: observer)
      “`

      RxCocoa
  • SharedSequenceConvertibleType

    withLatestFrom

    Extend withLatestFrom for support multi parameters

    “`
    let a = SharedSequenceConvertibleType.just(“A”)
    let b = SharedSequenceConvertibleType.just(“B”)
    let c = SharedSequenceConvertibleType.just(“C”)

    SharedSequenceConvertibleType().withLatestFrom(a, b, c)
    .subscribe(onNext: { (a, b, c) in

    })
    “`

    • withLatestFromAndSelf

      Extend withLatestFromAndSelf for combining parameters with self

      “`
      let a = SharedSequenceConvertibleType.just(“A”)
      let b = SharedSequenceConvertibleType.just(“B”)
      let c = SharedSequenceConvertibleType.just(“C”)

      SharedSequenceConvertibleType().withLatestFromAndSelf(a, b, c)
      .subscribe(onNext: { (a, b, c) in

      })
      “`


Installation


Used pods

Author

tokijh

License

RxSwiftExtensions is available under the MIT License See the LICENSE file for more info.

Latest podspec

{
    "name": "RxSwiftExtensions",
    "version": "1.2.3",
    "summary": "Frequently used extensoins in RxSwift",
    "homepage": "https://github.com/tokijh/RxSwiftExtensions",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "tokijh": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tokijh/RxSwiftExtensions.git",
        "tag": "1.2.3"
    },
    "swift_version": "4.2",
    "source_files": "RxSwiftExtensions/**/*.swift",
    "frameworks": "Foundation",
    "dependencies": {
        "RxSwift": [
            "~> 4.3"
        ],
        "RxCocoa": [
            "~> 4.3"
        ],
        "RxOptional": [
            "~> 3.5"
        ],
        "RxViewController": []
    },
    "platforms": {
        "ios": "8.0"
    }
}

Pin It on Pinterest

Share This