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

Realm begginers meetup

Realm begginers meetup

Realm quiz (performance, migraion)

Kishikawa Katsumi

July 24, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. ؙؒٔךػؿؓ٦وٝأ let articles = realm .objects(Article) ו׍׵ָ鸞ְד׃׳ֲ let recentArticles =

    realm.objects(Article) .filter("modificationDate > ...") .filter("deletionDate != nil") .sorted("modificationDate", ascending: false)
  2. ؙؒٔךػؿؓ٦وٝأחאְג ו׍׵׮ֿך儗挿דכ嗚稊勴⟝׾⥂䭯׃גְ׷׌ֽկ 㹋ꥷךؙؒٔכ㹋遤ׁ׸זְկ let articles = realm .objects(Article) let recentArticles

    = realm.objects(Article) .filter("modificationDate > ...") .filter("deletionDate != nil") .sorted("modificationDate", ascending: false)
  3. ؙؒٔךػؿؓ٦وٝأחאְג ו׍׵׮ֿך儗挿דכ嗚稊勴⟝׾⥂䭯׃גְ׷׌ֽկ 㹋ꥷךؙؒٔכ㹋遤ׁ׸זְկ let articles = realm .objects(Article) return articles.count

    let recentArticles = realm.objects(Article) .filter("modificationDate > ...") .filter("deletionDate != nil") .sorted("modificationDate", ascending: false) recentArticles[indexPath.row]
  4. ׮׃ָؙؒٔ鹼ְ㜥さכ غحؙؚٓؐٝسؙؒٔ׾ⵃ欽ׅ׷ notificationToken = realm.objects(Article) .filter("modificationDate > ...") .filter("deletionDate !=

    nil") .sorted("modificationDate", ascending: false) .addNotificationBlock { (changes: RealmCollectionChange) in switch changes { case let .Initial(results): ... case let .Update(results, deletions, insertions, modifications): ... case let .Error(error): ... } } ؙؒٔכغحؙؚٓؐٝسד㹋遤ׁ׸ծ 㸣✪׃׋儗挿ד؝٦ٕغحָؙㄎל׸׷
  5. و؎ؚٖ٦ءّٝ و؎ؚٖ٦ءّٝכ䗳銲 class User: Object { dynamic var id =

    0 dynamic var name = "" } class User: Object { dynamic var id = 0 dynamic var name = "" dynamic var age 0 }
  6. و؎ؚٖ٦ءّٝ و؎ؚٖ٦ءّٝכ䗳銲 class Article: Object {...} class Comment: Object {...}

    class User: Object {...} class Article: Object {...} class Comment: Object {...} class User: Object {...} class News: Object {...}
  7. و؎ؚٖ٦ءّٝ و؎ؚٖ٦ءّٝכ䗳銲 class User: Object { dynamic var id =

    0 dynamic var name = “" } class User: Object { dynamic var id = 0 dynamic var name = "" class override func indexedProperties() -> [String] { return ["name"] } }
  8. ꟼ鸬ך⵴ꤐ 剑䖓ךDPNNFOUDPVOUָ鵤ׅ⟝侧כ let article = realm.objects(Article)[0] let comments = article.comments

    print(comments.count) // => 3 let lastComment = comments[2] try! realm.write { realm.delete(lastComment) } print(comments.count) // => ?