Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1.12 KB

README.md

File metadata and controls

54 lines (39 loc) · 1.12 KB

RxPropertyWrappers.swift

Swift 5.1 Property Wrappers for RxSwift that allow you to expose non-mutable Observable types publicly, while wrapping them internally with mutable Subjects or Relays.

Examples

Subject wrappers

class SomeViewModel {
  
    @BehaviorSubjectWrapping(value: 0)
    var count: Observable<Int> // Type annotation is actually optional in this case
    
    @PublishSubjectWrapping
    var errors: Observable<String>
    
    func operation() {
      _count.onNext(1)
      _errors.onNext(SomeError.fail)
    }
}

enum SomeError {
  case fail
}

Relay wrappers

class SomeViewModel {
  
    @BehaviorRelayWrapping(value: 0)
    var count: Observable<Int> // Type annotation is actually optional in this case
    
    @PublishRelayWrapping
    var errors: Observable<String>
    
    func operation() {
      _count.accept(1)
      _errors.accept(SomeError.fail)
    }
}

enum SomeError {
  case fail
}

Installation

For now, feel free to copy-paste from the Sources directory :).