Update syntax for RxSwift2.x, Swift2.x
This commit is contained in:
parent
698a50b381
commit
9e8af26719
|
|
@ -46,7 +46,8 @@ let b /*: Observable<Int>*/ = 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<String>
|
||||
.map { WolframAlphaIsPrime($0.toInt() ?? 0) } // type is Observable<Observable<Prime>>
|
||||
.map { WolframAlphaIsPrime(Int($0) ?? 0) } // type is Observable<Observable<Prime>>
|
||||
.concat() // type is Observable<Prime>
|
||||
.map { "number \($0.n) is prime? \($0.isPrime)" } // type is Observable<String>
|
||||
.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<ValidationResult>`
|
||||
|
|
|
|||
Loading…
Reference in New Issue