Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let myStream = BehaviorSubject<Int>(value: 0)
- let startWithSubScribe = myStream
- .filter { (value) -> Bool in
- // ทำงานต่อเฉพาะค่าที่มากกว่า 2
- return value > 2
- }
- .startWith(0)
- .map { (value) -> String in
- // Change Int to String
- return "My Number is \(value)"
- }
- .startWith("5555555")
- .subscribe(onNext: { (value) in
- print("On Next: [\(value)]")
- })
- myStream.onNext(1)
- myStream.onNext(2)
- myStream.onNext(3)
- myStream.onNext(4)
- // -----------------[Example of StartWith]---------------
- //
- // On Next: [5555555]
- // On Next: [My Number is 0]
- // On Next: [My Number is 3]
- // On Next: [My Number is 4]
- //
- // ------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement