美文网首页
闭包(Block)转换为可观察序列

闭包(Block)转换为可观察序列

作者: FallPine | 来源:发表于2018-09-14 17:02 被阅读8次
    • 以MJRefresh为例

    extension Reactive where Base: MJRefreshComponent {
        /// 正在刷新
        var qs_refreshing: ControlEvent<Void> {
            let source: Observable<Void> = Observable.create {
                [weak control = self.base] observer -> Disposable  in
                MainScheduler.ensureExecutingOnScheduler()
                
                guard let control = control else {
                    observer.on(.completed)
                    return Disposables.create()
                }
                
                control.refreshingBlock = {
                    observer.on(.next(()))
                }
                return Disposables.create()
                }
                .takeUntil(deallocated)
            
            return ControlEvent(events: source)
        }
    }
    

    相关文章

      网友评论

          本文标题:闭包(Block)转换为可观察序列

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