美文网首页RxSwift源码解析
DelegateProxy 消息转发策略验证

DelegateProxy 消息转发策略验证

作者: 狼性刀锋 | 来源:发表于2018-11-10 18:18 被阅读19次

    DelegateProxy 消息转发策略验证

    实现思想

    1. 订阅一个能触发消息转发的Observable
    2. 用户操作触发delegate
    3. 打印responds 结果 , 结果应该是ture
    4. 通过一个开关按钮,取消订阅
    5. 用户再次操作, 观察结果, 此时应该为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.
        }
        */
    
    }
    
    
    
    

    结论

    实验结果符合预期, 也就是说整个消息转发是按需的, 没有订阅者就不会转发消息,避免无谓的性能损害。

    相关文章

      网友评论

        本文标题:DelegateProxy 消息转发策略验证

        本文链接:https://www.haomeiwen.com/subject/hjftfqtx.html