Ace Green
Ace Green

Reputation: 391

RxSwift equivalent BehaviorSubject's .modify() method

Reactive BehaviorSubject has a modify method while exposes the values as inout and allows you to modify them. Any RxSwift property that allows similar behaviour?

Upvotes: 0

Views: 302

Answers (1)

CloakedEddy
CloakedEddy

Reputation: 1995

I'm not aware of any property that allows this, but you could write your own extension for this.

extension BehaviorRelay {
    var inoutValue: Element {
        get { return value }
        set { accept(newValue) }
    }
}

// for example
extension BehaviorRelay where Element == Int {
    func increment() {
        inoutValue += 1
    }
}

Upvotes: 1

Related Questions