From 84c42e6dd67a800b6547292f101f435554270d7e Mon Sep 17 00:00:00 2001 From: Scott Gardner Date: Sat, 14 May 2016 16:50:47 -0500 Subject: [PATCH] Split Error Handling and Debugging Operators into separate pages --- .../Contents.swift | 83 +++++++++++++++++++ .../Contents.swift | 71 ---------------- .../Contents.swift | 3 +- Rx.playground/contents.xcplayground | 3 +- 4 files changed, 87 insertions(+), 73 deletions(-) create mode 100644 Rx.playground/Pages/Debugging_Operators.xcplaygroundpage/Contents.swift rename Rx.playground/Pages/{Error_Handling_and_Debugging_Operators.xcplaygroundpage => Error_Handling_Operators.xcplaygroundpage}/Contents.swift (69%) diff --git a/Rx.playground/Pages/Debugging_Operators.xcplaygroundpage/Contents.swift b/Rx.playground/Pages/Debugging_Operators.xcplaygroundpage/Contents.swift new file mode 100644 index 000000000..fdde6b681 --- /dev/null +++ b/Rx.playground/Pages/Debugging_Operators.xcplaygroundpage/Contents.swift @@ -0,0 +1,83 @@ +/*: + > # IMPORTANT: To use **Rx.playground**: + 1. Open **Rx.xcworkspace**. + 1. Build the **RxSwift-OSX** scheme (**Product** → **Build**). + 1. Open **Rx** playground in the **Project navigator**. + 1. Show the Debug Area (**View** → **Debug Area** → **Show Debug Area**). + ---- + [Previous](@previous) - [Table of Contents](Table_of_Contents) + */ +import RxSwift +/*: + # Debugging Operators + Operators to help debug Rx code. + ## `debug` + Prints out all subscriptions, events, and disposals. + */ +example("debug") { + let disposeBag = DisposeBag() + var count = 1 + + let sequenceThatErrors = Observable.create { observer in + observer.onNext("🍎") + observer.onNext("🍐") + observer.onNext("🍊") + + if count < 5 { + observer.onError(Error.Test) + print("Error encountered") + count += 1 + } + + observer.onNext("🐶") + observer.onNext("🐱") + observer.onNext("🐭") + observer.onCompleted() + + return NopDisposable.instance + } + + sequenceThatErrors + .retry(3) + .debug() + .subscribeNext { print($0) } + .addDisposableTo(disposeBag) +} +/*: + ---- + ## `RxSwift.resourceCount` + Provides a count of all Rx resource allocations, which is useful for detecting leaks during development. + */ +#if NOT_IN_PLAYGROUND +#else +example("RxSwift.resourceCount") { + print(RxSwift.resourceCount) + + let disposeBag = DisposeBag() + + print(RxSwift.resourceCount) + + let variable = Variable("🍎") + + let subscription1 = variable.asObservable().subscribeNext { print($0) } + + print(RxSwift.resourceCount) + + let subscription2 = variable.asObservable().subscribeNext { print($0) } + + print(RxSwift.resourceCount) + + subscription1.dispose() + + print(RxSwift.resourceCount) + + subscription2.dispose() + + print(RxSwift.resourceCount) +} + +print(RxSwift.resourceCount) +#endif +//: > `RxSwift.resourceCount` is not enabled by default, and should generally not be enabled in Release builds. [Click here](Enable_RxSwift.resourceCount) for instructions on how to enable it. + +//: [Table of Contents](Table_of_Contents) diff --git a/Rx.playground/Pages/Error_Handling_and_Debugging_Operators.xcplaygroundpage/Contents.swift b/Rx.playground/Pages/Error_Handling_Operators.xcplaygroundpage/Contents.swift similarity index 69% rename from Rx.playground/Pages/Error_Handling_and_Debugging_Operators.xcplaygroundpage/Contents.swift rename to Rx.playground/Pages/Error_Handling_Operators.xcplaygroundpage/Contents.swift index 43228d359..f20c87215 100644 --- a/Rx.playground/Pages/Error_Handling_and_Debugging_Operators.xcplaygroundpage/Contents.swift +++ b/Rx.playground/Pages/Error_Handling_Operators.xcplaygroundpage/Contents.swift @@ -127,76 +127,5 @@ example("retry maxAttemptCount") { .subscribeNext { print($0) } .addDisposableTo(disposeBag) } -/*: - # Debugging Operators - Operators to help debug Rx code. - ## `debug` - Prints out all subscriptions, events, and disposals. - */ -example("debug") { - let disposeBag = DisposeBag() - var count = 1 - - let sequenceThatErrors = Observable.create { observer in - observer.onNext("🍎") - observer.onNext("🍐") - observer.onNext("🍊") - - if count < 5 { - observer.onError(Error.Test) - print("Error encountered") - count += 1 - } - - observer.onNext("🐶") - observer.onNext("🐱") - observer.onNext("🐭") - observer.onCompleted() - - return NopDisposable.instance - } - - sequenceThatErrors - .retry(3) - .debug() - .subscribeNext { print($0) } - .addDisposableTo(disposeBag) -} -/*: - ---- - ## `RxSwift.resourceCount` - Provides a count of all Rx resource allocations, which is useful for detecting leaks during development. - */ -#if NOT_IN_PLAYGROUND -#else -example("RxSwift.resourceCount") { - print(RxSwift.resourceCount) - - let disposeBag = DisposeBag() - - print(RxSwift.resourceCount) - - let variable = Variable("🍎") - - let subscription1 = variable.asObservable().subscribeNext { print($0) } - - print(RxSwift.resourceCount) - - let subscription2 = variable.asObservable().subscribeNext { print($0) } - - print(RxSwift.resourceCount) - - subscription1.dispose() - - print(RxSwift.resourceCount) - - subscription2.dispose() - - print(RxSwift.resourceCount) -} - -print(RxSwift.resourceCount) -#endif -//: > `RxSwift.resourceCount` is not enabled by default, and should generally not be enabled in Release builds. [Click here](Enable_RxSwift.resourceCount) for instructions on how to enable it. //: [Table of Contents](Table_of_Contents) diff --git a/Rx.playground/Pages/Table_of_Contents.xcplaygroundpage/Contents.swift b/Rx.playground/Pages/Table_of_Contents.xcplaygroundpage/Contents.swift index 73e037086..1b8c5a2b2 100644 --- a/Rx.playground/Pages/Table_of_Contents.xcplaygroundpage/Contents.swift +++ b/Rx.playground/Pages/Table_of_Contents.xcplaygroundpage/Contents.swift @@ -14,7 +14,8 @@ 1. [Filtering and Conditional Operators](Filtering_and_Conditional_Operators) 1. [Mathematical and Aggregate Operators](Mathematical_and_Aggregate_Operators) 1. [Connectable Operators](Connectable_Operators) - 1. [Debugging and Error Handling Operators](Debugging_and_Error_Handling_Operators) + 1. [Error Handling Operators](Error_Handling_Operators) + 1. [Debugging Operators](Debugging_Operators) */ //: [Next](@next) diff --git a/Rx.playground/contents.xcplayground b/Rx.playground/contents.xcplayground index 9fe3cfd0b..5565f6f90 100644 --- a/Rx.playground/contents.xcplayground +++ b/Rx.playground/contents.xcplayground @@ -10,7 +10,8 @@ - + + \ No newline at end of file