目錄:
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 endcarthage
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