0

I want to assign a value to an BehaviorRelay in RxSwift - RxCocoa. But I get this error message: "Cannot assign to property: 'value' is a get-only property".

Thats my code: private var todos = BehaviorRelay<[MainToDoData]>(value: []) todos.value = todosVM.data

2 Answers2

2

You should use accept:

todos.accept(todosVM.data)
hell0friend
  • 561
  • 1
  • 3
  • 4
0

Jump to Definition in BehaviorRelay

You can see this:

/// Accepts `event` and emits it to subscribers    
public func accept(_ event: Element)

/// Current value of behavior subject
public var value: Element { get }

value is a get value.

use accept(_ event: Element) like todos.accept(todosVM.data)

LeeWu
  • 252
  • 2
  • 5