Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxSwift

 RxSwift

USAMI Kosuke

August 26, 2015
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. Reactive Programming for iOS 4 ReactiveCocoa 4 ReactKit 4 RxSwift

    4 ͻͱͪ͘ʹ Reactive ͱ͍ͬͯ΋ߟ͑ํ͕ͪΐͬͱͣͭҧ ͏ 4 ͦΕͧΕʹྑ͕͋͞Δ
  2. RxSwift ͷಛ௃ 4 ReactiveX ϑΝϛϦʔ 4 ࠷ۙਖ਼ࣜʹՃΘͬͨ 4 Swift ωΠςΟϒ

    4 ίΞʢRxSwiftʣ͸ Swift ͷΈ 4 Ұ෦ʢRxCocoaʣ͸ Objective-C ΛؚΉ
  3. ReactiveX 4 http://reactivex.io 4 ֤ݴޠ൛͕͋Δ 4 Rx.NET (C#) 4 RxJava

    4 RxJS 4 RxSwift 4 ɾɾɾͳͲ 4 Learn once, apply anywhere
  4. RxSwift ͷಋೖ 4 Dynamic Library ͱͯ͠ಋೖʢiOS 8 Ҏ߱ʣ 4 CocoaPods

    4 Carthage 4 ϓϩδΣΫτ಺ʹ૊ΈࠐΈʢiOS 7 ରԠʣ 4 CocoaSeeds
  5. RxSwift / RxCocoa 4 RxSwift 4 Observable / ֤छ Operator

    / Scheduler ͳͲ 4 RxCocoa 4 UIKit / NSURLSession / KVO ͳͲ
  6. Examples 1 combineLatest(firstNameLabel.rx_text, lastNameLabel.rx_text) { $0 + " " +

    $1 } >- map { "Greeting \($0)" } >- subscribeNext { greeting in greetingLabel.text = greeting }
  7. Examples 2 let userRequest: Observable<User> = API.getUser("me") let friendsRequest: Observable<[Friend]>

    = API.getFriends("me") zip(userRequest, friendsRequest) { user, friends in return (user, friends) } >- observeOn(MainScheduler.sharedInstance) >- subscribeNext { (user, friends) in // bind to UI }
  8. Examples 3 searchTextField.rx_text >- throttle(0.5, MainScheduler.sharedInstance) >- distinctUntilChanged() >- map

    { query in API.getSearchResults(query) >- retry(3) >- startWith([]) >- catchError([]) } >- switchLatest >- map { results in // bind to UI }
  9. RxSwift 2.0 4 ݱࡏ։ൃதʢGit ϒϥϯν rxswift-2.0ʣ 4 Swift 2 ରԠ

    4 ԋࢉࢠ͕ >- ͔Β . ʹมߋ 4 ಺෦ϩδοΫ : RxResult ͔Β try - catch ʹ