Olga
Olga

Reputation: 1

Updating the value of BehaviorRelay property

When I try to set a value, I have an error:

Cannot assign to property: 'value' is a get-only property

var value: BehaviorRelay<Any?>

var unpackedValue: Any? {
    get {
        return value.value
    }

    set {
        value.value  = newValue // error
    }
}

Upvotes: 0

Views: 1013

Answers (1)

Witek Bobrowski
Witek Bobrowski

Reputation: 4239

on BehaviorRelay properies you need to use accept(_ event: Element) to send a new value

var unpackedValue: Any? {
    get {
        return value.value
    }
    set {
       value.accept(newValue)
    }
}

Refer to the implementation of BehaviorRelay

Accepts event and emits it to subscribers

Upvotes: 3

Related Questions