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

调试模式,会输出运行过程的一些详细信息

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

可以用来查看当前所有的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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,881评论 18 139
  • 现在开始 observable 和 Subject 的实操了. 从下面开始, 就来看看如何在实际的开发过程中去运用...
    貘鸣阅读 823评论 0 1
  • 前言 iOS开发会经常用到cocoapods管理第三方,简单、方便、高效。如何集成cocoapods在cocoap...
    Moker_C阅读 875评论 0 1
  • 2.podfile文件讲解 podfile是一个规范文件,描述一个或多个项目目标依赖项,CocoaPods管理iO...
    coderPoo阅读 10,153评论 0 13
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,719评论 0 3