Pro Yearly is on sale from $80 to $50! »

Realm Centered Design

Realm Centered Design

Realm, RxSwift, RxRealm MVVM

Acbf3391de0494432a92221ffe89f34e?s=128

yohei sugigami

August 23, 2016
Tweet

Transcript

  1. yohei SUGIGAMI Realm Centered Design RxSwift+RxRealm(RealmNotification) Aug. 23, 2016 @

    Wantedly potatotips #32 Realmத৺ઃܭ
  2. γΰτͰίίϩΦυϧ ਿ্ ༸ฏ Yohei SUGIGAMI ID susieyy TwitterˍQiitaˍGithub

  3. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 realm notificationΛ஌ͬͯ·͔͢ʁ

  4. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 addNotificationBlockϝιουͰϒϩοΫΛ ొ࿥͢ΔͱΦϒδΣΫτ͕ߋ৽͞Εͨͱ͖

    ௨஌Λड͚Δ͜ͱ͕ͰΔ ʢਆػೳʣ
  5. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Aը໘ Bը໘

    WriteTx Notification Aը໘ͰͷมߋΛBը໘ʹ௨஌Ͱ͖Δ
  6. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Code example

    ͱ͘ʹ഑ྻσʔλͷ؂ࢹͷ ࠩ෼Index௨஌͕͢͹Β͍͠ʂ
  7. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 RxSwift RxRealm

    x meets
  8. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 try! Realm().objects(ContactRealm).asObservableChangeset()

    .subscribeNext { [weak self] results, changeset in guard let tableView = self?.tableView else { return } self?.results = results if let changeset = changeset { tableView.beginUpdates() tableView.insertRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.deleteRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.reloadRowsAtIndexPaths(…, withRowAnimation: .Automatic) tableView.endUpdates() } else { tableView.reloadData() } }.addDisposableTo(disposeBag) NotificationΛRxSwiftͷObservableͱͯ͠ѻ͑Δʂ
  9. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 // Simple

    Create [MessageRealm("hello"), MessageRealm("world")] .toObservable() .subscribe(Realm.rx_add()) // With API let request = API.Endpoint.MessagesRequest().request() Session.rx_response(request) .subscribe(Realm.rx_add()) RealmObjectͷCRUD΋RwSwiftͷ؅ཧԼʹʂ
  10. γΰτͰίίϩΦυϧ B Launch iPhone3G iOS Developer since mid 2008 RxSwift

    MVVM Realm Centered Design RxRealm
  11. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ RxSwift w/ MVVM ը໘ͷओཁͳσʔλ ը໘ԣஅతͳσʔλͷѻ͍͕೉͍͠ ʢLike໰୊ʣ
  12. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Subscribe ը໘ԣஅతͳঢ়ଶɾσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift w/ MVVM(earth) ը໘ͷओཁͳσʔλ Global ViewModel ©
  13. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 View ViewModel

    Aը໘ Bը໘ Cը໘ Observable Store Subscribe ը໘ԣஅͳঢ়ଶ ը໘ͷओཁͳσʔλ ௨৴தͳͲը໘ݻ༗ͷঢ়ଶ earth (Singleton) ஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ RxSwift+RxRealm w/ MVVM (RxRealm)
  14. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 Redux -

    Single source of truth - State is read-only - Changes are made with pure functions ΞϓϦͷঢ়ଶɾσʔλΛอ࣋͢ΔStore͸ͨͩ1ͭ Inspired by
  15. γΰτͰίίϩΦυϧ Launch iPhone3G iOS Developer since mid 2008 ΫϥΠΞϯτΞϓϦ͸ঢ়ଶɾσʔλ؅ཧ͸ෳࡶ -

    ෭࣍తͳ࢈෺ͱͯ͠ɺRxDatasourceʹΑΔTableViewBinding͸࢖͍ʹ ͍͘ͷͰRealmNotificationʹΑΔTableViewReload͸ѻ͍΍͍͢ 㱺 Rx w/ MVVMͱReduxͷ͍͍ͱ͜ΖͲΓΛ͍ͨ͠ - ը໘ʹඥͮ͘σʔλͱঢ়ଶΛViewModelʹ٧ΊΔͷ΋ɺΞϓϦશମͷσʔλͱ ঢ়ଶΛStoreʹ٧ΊΔͷ΋྆ۃ୺Ͱਏ͍ - “஍ٿ͸Ͱ͔͍ͬγϯάϧτϯ”͸ΤϙοΫϝΠΩϯά - ը໘ʹඥͮ͘ঢ়ଶΛ֤ViewModelʹσʔλΛStoreʢRealm or Singletonʣ ʹͱ͍͏ં஭ҊΛߟ͑ͨ ·ͱΊ
  16. 5IBOLZPV