Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RxSwift:如何向int值添加简单观察者_Swift_Rx Swift_Observers - Fatal编程技术网

RxSwift:如何向int值添加简单观察者

RxSwift:如何向int值添加简单观察者,swift,rx-swift,observers,Swift,Rx Swift,Observers,我想使用rxswift来观察我的模型的散列值 我有类似注册表的东西,只有在某些数据发生更改时,我才需要显示“保存更改” 我没有使用任何绑定 我只想观察数据的散列。代码和解释:- //Variable where you can store value as well as you can keep watch on change let aVar:BehaviorRelay<Int> = BehaviorRelay(value : 0) let disposeBag = Disp

我想使用rxswift来观察我的模型的散列值

我有类似注册表的东西,只有在某些数据发生更改时,我才需要显示“保存更改”

我没有使用任何绑定


我只想观察数据的散列。

代码和解释:-

//Variable where you can store value as well as you can keep watch on change
 let aVar:BehaviorRelay<Int> = BehaviorRelay(value : 0)
 let disposeBag = DisposeBag()

  //Observe changes 
  aVar.asObservable().subscribe(onNext: {_ in
    //Do whatever you need to do here 
    }, onError: nil, onCompleted: nil, onDisposed: nil).disposed(by: disposeBag)
//变量,您可以在其中存储值并监视更改
设aVar:BehaviorRelay=BehaviorRelay(值:0)
设disposeBag=disposeBag()
//观察变化
aVar.asObservable()
//在这里做你需要做的一切
},onError:nil,onCompleted:nil,onDisposed:nil)。已处置(被处置者:disposeBag)

您可以尝试使用BehaviorRelay及其可观察性。@Leena您能举个例子吗?