Rx.playground学习

2016-12-22  本文已影响55人  cocoaroger

基础概念

_ = Observable<String>.create { observerOfString -> Disposable in
        print("This will never be printed")
        observerOfString.on(.next("😬"))
        observerOfString.on(.completed)
        return Disposables.create()
    }

使用Observable创建和订阅Sequence

使用Subject创建Sequence

合并操作Combination Operators

传输操作Transforming Operators

过滤操作Filtering and Conditional Operators

集合操作Mathematical and Aggregate Operators

Observable.range(start: 1, count: 10)
        .toArray()
        .subscribe { print($0) }
        .addDisposableTo(disposeBag)
Observable.of(10, 100, 1000)
        .reduce(1, accumulator: +)   // 求+运算,1+10+100+1000
        .subscribe(onNext: { print($0) })
        .addDisposableTo(disposeBag)
         let disposeBag = DisposeBag()
         let subject1 = BehaviorSubject(value: "🍎")
         let subject2 = BehaviorSubject(value: "🐶")
         let variable = Variable(subject1)
    
         variable.asObservable()
           .concat()
           .subscribe { print($0) }
           .addDisposableTo(disposeBag)
        subject1.onNext("🍐")
        subject1.onNext("🍊")

        variable.value = subject2
    
        subject2.onNext("I would be ignored")
        subject2.onNext("🐱")
    
        subject1.onCompleted()
    
        subject2.onNext("🐭")

    //  在subject1调用onCompleted()之前,subject2都收不到信号

可连接的操作Connectable Operators

错误处理机制Error Handling Operators

调试Debugging Operators

Enable RxSwift.resourceCount

Follow these instructions to enable RxSwift.Resources.total in your project:

  1. Add a post_install hook to your Podfile, e.g.:
    target 'AppTarget' do
    pod 'RxSwift'
    end

    post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'RxSwift'
            target.build_configurations.each do |config|
                if config.name == 'Debug'
                    config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['-D', 'TRACE_RESOURCES']
                end
            end
        end
    end
end
  1. Run pod update.
  2. Build project (ProductBuild).
  1. Run carthage build --configuration Debug.
  2. Build project (ProductBuild).
上一篇 下一篇

猜你喜欢

热点阅读