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

Realm Japan meetup #14

Realm Japan meetup #14

- Fine-grained Notifications
- Linking objects properties

Kishikawa Katsumi

July 24, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. -JOLJOHPCKFDUTQSPQFSUJFT class Person: Object { dynamic var name = ""

    dynamic var age = 0 let dogs = List<Dog>() } class Dog: Object { dynamic var name = "" var owners: [Person] { return linkingObjects(Person.self, forProperty: "dogs") } }
  2. -JOLJOHPCKFDUTQSPQFSUJFT class Person: Object { dynamic var name = ""

    dynamic var age = 0 let dogs = List<Dog>() } class Dog: Object { dynamic var name = "" var owners: [Person] { return linkingObjects(Person.self, forProperty: "dogs") } }
  3. -JOLJOHPCKFDUTQSPQFSUJFT class Person: Object { dynamic var name = ""

    dynamic var age = 0 let dogs = List<Dog>() } class Dog: Object { dynamic var name = "" let owners = LinkingObjects(fromType: Person.self, property: "dogs") }
  4. -JOLJOHPCKFDUTQSPQFSUJFT class Person: Object { dynamic var name = ""

    dynamic var age = 0 let dogs = List<Dog>() } class Dog: Object { dynamic var name = "" let owners = LinkingObjects(fromType: Person.self, property: "dogs") }
  5. 'JOFHSBJOFE/PUJDBUJPO let dogs = realm.objects(Dog) token = dogs.addNotificationBlock { (change:

    RealmCollectionChange) in switch change { case let .Initial(change): ... case let .Update(change, deletions, insertions, modifications): ... case let .Error(error): ... } }
  6. token = dogs.addNotificationBlock { (change: RealmCollectionChange) in switch change {

    case let .Initial(change): self.tableView.reloadData() case let .Update(change, deletions, insertions, modifications): self.tableView .beginUpdates() self.tableView .deleteRowsAtIndexPaths( deletions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView .insertRowsAtIndexPaths( insertions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView.endUpdates() ...
  7. token = dogs.addNotificationBlock { (change: RealmCollectionChange) in switch change {

    case let .Initial(change): self.tableView.reloadData() case let .Update(change, deletions, insertions, modifications): self.tableView .beginUpdates() self.tableView .deleteRowsAtIndexPaths( deletions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView .insertRowsAtIndexPaths( insertions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView.endUpdates() ...
  8. token = dogs.addNotificationBlock { (change: RealmCollectionChange) in switch change {

    case let .Initial(change): self.tableView.reloadData() case let .Update(change, deletions, insertions, modifications): self.tableView .beginUpdates() self.tableView .deleteRowsAtIndexPaths( deletions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView .insertRowsAtIndexPaths( insertions.map { NSIndexPath(forRow: $0, inSection: 0) }, withRowAnimation: .Automatic) self.tableView.endUpdates() ...
  9. favorites = realm .objects(Tweet) .filter("favorited = %@", true) .sorted("createdAt", ascending:

    false) token = favorites?.addNotificationBlock { [weak self] (change: RealmCollectionChange) in ... self?.tableView.reloadData() } timeline = realm .objects(Tweet) .sorted("createdAt", ascending: false) token = timeline?.addNotificationBlock { [weak self] (change: RealmCollectionChange) in ... self?.tableView.reloadData() } 3FTVMUTח㢌⻉ָ֮׏׋儗׌ֽ鸐濼ׁ׸׷״ֲח
  10. favorites = realm .objects(Tweet) .filter("favorited = %@", true) .sorted("createdAt", ascending:

    false) token = favorites?.addNotificationBlock { [weak self] (change: RealmCollectionChange) in ... self?.tableView.reloadData() } timeline = realm .objects(Tweet) .sorted("createdAt", ascending: false) token = timeline?.addNotificationBlock { [weak self] (change: RealmCollectionChange) in ... self?.tableView.reloadData() } 3FTVMUTח㢌⻉ָ֮׏׋儗׌ֽ鸐濼ׁ׸׷״ֲח