From 9e8af26719b429cb1f99f5230d7a67286e41f5b0 Mon Sep 17 00:00:00 2001 From: dakeshi Date: Thu, 17 Mar 2016 18:02:07 +0900 Subject: [PATCH] Update syntax for RxSwift2.x, Swift2.x --- Documentation/Examples.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/Examples.md b/Documentation/Examples.md index ae81a65b..135898f2 100644 --- a/Documentation/Examples.md +++ b/Documentation/Examples.md @@ -46,7 +46,8 @@ let b /*: Observable*/ = Variable(2) // b = 2 // if a + b >= 0 { // c = "\(a + b) is positive" // } -let c = Observable.combineLatest(a, b) { $0 + $1 } // combines latest values of variables `a` and `b` using `+` +let c = Observable.combineLatest(a.asObservable(), b.asObservable(), + resultSelector: { $0 + $1 }) // combines latest values of variables `a` and `b` using `+` .filter { $0 >= 0 } // if `a + b >= 0` is true, `a + b` is passed to map operator .map { "\($0) is positive" } // maps `a + b` to "\(a + b) is positive" @@ -87,7 +88,7 @@ b.value = -8 // doesn't print anything ```swift let subscription/*: Disposable */ = primeTextField.rx_text // type is Observable - .map { WolframAlphaIsPrime($0.toInt() ?? 0) } // type is Observable> + .map { WolframAlphaIsPrime(Int($0) ?? 0) } // type is Observable> .concat() // type is Observable .map { "number \($0.n) is prime? \($0.isPrime)" } // type is Observable .bindTo(resultLabel.rx_text) // return Disposable that can be used to unbind everything @@ -124,7 +125,7 @@ self.usernameOutlet.rx_text // Convenience for constructing synchronous result. // In case there is mixed synchronous and asychronous code inside the same // method, this will construct an async result that is resolved immediatelly. - return just((valid: false, message: "Username can't be empty.")) + return Observable.just((valid: false, message: "Username can't be empty.")) } ... @@ -136,7 +137,8 @@ self.usernameOutlet.rx_text // * true - is valid // * false - not valid // * nil - validation pending - let loadingValue = (valid: nil, message: "Checking availability ...") + typealias LoadingInfo = (valid : String?, message: String?) + let loadingValue : LoadingInfo = (valid: nil, message: "Checking availability ...") // This will fire a server call to check if the username already exists. // Guess what, its type is `Observable`