-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Error Handling and Debugging Operators into separate pages
- Loading branch information
Showing
4 changed files
with
87 additions
and
73 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Rx.playground/Pages/Debugging_Operators.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>.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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters