Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxSwift : BehaviorRelay in place of Variable usage

I'm new to RxSwift and reading about subjects, I tried Variable Subject. Which in turns giving Warning in console

ℹ️ [DEPRECATED] `Variable` is planned for future deprecation. Please consider `BehaviorRelay` as a replacement. Read more at: https://git.io/vNqvx

Earlier I have declared Variable like this

var searchItems = Variable<[MyClass]>([])

So i have done basic array operations from it's property called value as it was get set property like

 1. self.searchItems.value.removeAll()
 2. self.searchItems.value.append(items)
 3. self.searchItems.value = items

Now After getting warning i changed it to BehaviorRelay like

var searchItems = BehaviorRelay<[MyClass]>(value: [])

So I got error that value is get property only.

I googled alot but can't get suitable explanations for Array operations.

I only got a code self.searchItems.accept(items) which i really don't know what it exactly do add fresh items or append.

I needed how all 4 operations will be performed when using BehaviorRelay?

like image 234
Abhishek Thapliyal Avatar asked Dec 17 '22 20:12

Abhishek Thapliyal


1 Answers

1) Remove all

var array = self.searchItems.value
array.removeAll()
self.searchItems.accept(array)

2) Append item

self.searchItems.value.accept(searchItems + [items])

3) Value = ...

self.searchItems.value.accept(items)
like image 174
maxwell Avatar answered Dec 28 '22 08:12

maxwell