rx-swift

RxSwift map and flatMap difference

我的未来我决定 提交于 2019-11-29 10:31:57
问题 I can't understand the difference between map and flatMap In RxSwift. In the RxSwift playground examples and the books, flatMap is used as converting Observables which has inner Observable property. However I see flatMap being used directly on Observable of basic types. For example for below code, both of them produces the same output. Can someone help me to understand the difference between map and flatMap struct Student { let score:Int } let ryan = Student(score:80) let student =

RxSwift and isSelected property on UIButton

时光总嘲笑我的痴心妄想 提交于 2019-11-29 03:59:02
问题 I have three buttons and I want them to be selected only one at a time: and: etc... My approach is this: class MyController: UIViewController { @IBOutlet var buttonOne: UIButton! @IBOutlet var buttonTwo: UIButton! @IBOutlet var buttonThree: UIButton! var buttonOneIsSelected = Variable(true) var buttonTwoIsSelected = Variable(false) var buttonThreeIsSelected = Variable(false) override func viewDidLoad() { super.viewDidLoad() buttonOne.isSelected = true buttonOneIsSelected.asDriver() .drive

RxSwift merge different kind of Observables

99封情书 提交于 2019-11-28 10:54:48
How should I merge 2 different types of Observable s in RxSwift? For example: var a: Observable<Int> var b: Observable<Void> Observable.of(a,b).merge() is not possible because of type parameter difference. To merge them, they need to have the same type for their Element . So, one option is to throw away their type information and cast to AnyObject . Now they can be merged: let stringSubject = PublishSubject<String>() let stringObservable = stringSubject.asObservable().map { $0 as AnyObject } let intSubject = PublishSubject<Int>() let intObservable = intSubject.asObservable().map { $0 as

RxSwift merge different kind of Observables

杀马特。学长 韩版系。学妹 提交于 2019-11-27 03:53:52
问题 How should I merge 2 different types of Observable s in RxSwift? For example: var a: Observable<Int> var b: Observable<Void> Observable.of(a,b).merge() is not possible because of type parameter difference. 回答1: To merge them, they need to have the same type for their Element . So, one option is to throw away their type information and cast to AnyObject . Now they can be merged: let stringSubject = PublishSubject<String>() let stringObservable = stringSubject.asObservable().map { $0 as