RxSwift Debug Operators

目錄:

RxSwift - 入門
RxSwift Observable Create
RxSwift Subject
RxSwift Combination Operators
RxSwift Transforming Operators
RxSwift Filterning and conditional operators
RxSwift Mathematical and aggregate operators
RxSwift Connectable Operators
RxSwift ErrorHandding Operators
RxSwift Debug Operators


Demo地址


debug

調(diào)試模式,會輸出運行過程的一些詳細(xì)信息

example("debug") {
            let bag = DisposeBag()
            var count = 1
            
            let sequenceThatErrors = Observable<String>.create { observer in
                observer.onNext("??")
                observer.onNext("??")
                observer.onNext("??")
                
                if count < 5 {
                    observer.onError(TestError.test)
                    print("Error encountered")
                    count += 1
                }
                
                observer.onNext("??")
                observer.onNext("??")
                observer.onNext("??")
                observer.onCompleted()
                
                return Disposables.create()
            }
            
            sequenceThatErrors
                .retry(3)
                .debug()
                .subscribe(onNext: { print($0) })
                .disposed(by: bag)
        }
---------- debug ----------
2018-10-09 22:02:05.737: Debug.swift:39 (init()) -> subscribed
2018-10-09 22:02:05.788: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.790: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.790: Debug.swift:39 (init()) -> Event next(??)
??
Error encountered
2018-10-09 22:02:05.798: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.799: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.799: Debug.swift:39 (init()) -> Event next(??)
??
Error encountered
2018-10-09 22:02:05.799: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.800: Debug.swift:39 (init()) -> Event next(??)
??
2018-10-09 22:02:05.800: Debug.swift:39 (init()) -> Event next(??)
??
Error encountered
2018-10-09 22:02:05.812: Debug.swift:39 (init()) -> Event error(test)
Unhandled error happened: test
 subscription called from:

2018-10-09 22:02:05.812: Debug.swift:39 (init()) -> isDisposed


Resources.total

可以用來查看當(dāng)前所有的Observable,可便于我們查看某些資源是否釋放。

使用其需要做一些特殊操作

cocoaPods

use_frameworks!

target 'RxSwiftDemo' do
    pod 'RxSwift',    '~> 4.0'
    pod 'RxCocoa',    '~> 4.0'
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

carthage

carthage build --configuration Debug.
example("RxSwift.Resources.total") {
    print(RxSwift.Resources.total)
    
    let disposeBag = DisposeBag()
    
    print(RxSwift.Resources.total)
    
    let variable = Variable("??")
    
    let subscription1 = variable.asObservable().subscribe(onNext: { print($0) })
    
    print(RxSwift.Resources.total)
    
    let subscription2 = variable.asObservable().subscribe(onNext: { print($0) })
    
    print(RxSwift.Resources.total)
    
    subscription1.dispose()
    
    print(RxSwift.Resources.total)
    
    subscription2.dispose()
    
    print(RxSwift.Resources.total)
}
    
print(RxSwift.Resources.total)
---------- RxSwift.Resources.total ----------
1
?? [DEPRECATED] `Variable` is planned for future deprecation. Please consider `BehaviorRelay` as a replacement. Read more at: https://git.io/vNqvx
??
10
??
13
11
9
1
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,564評論 19 139
  • 現(xiàn)在開始 observable 和 Subject 的實操了. 從下面開始, 就來看看如何在實際的開發(fā)過程中去運用...
    貘鳴閱讀 888評論 0 1
  • 前言 iOS開發(fā)會經(jīng)常用到cocoapods管理第三方,簡單、方便、高效。如何集成cocoapods在cocoap...
    Moker_C閱讀 919評論 0 1
  • 2.podfile文件講解 podfile是一個規(guī)范文件,描述一個或多個項目目標(biāo)依賴項,CocoaPods管理iO...
    coderPoo閱讀 10,416評論 0 13
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom閱讀 3,203評論 0 3

友情鏈接更多精彩內(nèi)容