DelegateProxy 消息转发策略验证
2018-11-10 本文已影响19人
狼性刀锋
DelegateProxy 消息转发策略验证
实现思想
- 订阅一个能触发消息转发的Observable
- 用户操作触发delegate
- 打印responds 结果 , 结果应该是ture
- 通过一个开关按钮,取消订阅
- 用户再次操作, 观察结果, 此时应该为false
简单demo
class TextViewController: UIViewController {
var scrollViewDisposable: Disposable!
@IBAction func cancel(_ sender: Any) {
print("cancel")
scrollViewDisposable.dispose()
}
//@IBOutlet weak var textview: UITextView!
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
scrollViewDisposable = scrollView.rx.didEndDecelerating.subscribe { print($0) }
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
结论
实验结果符合预期, 也就是说整个消息转发是按需的, 没有订阅者就不会转发消息,避免无谓的性能损害。