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

Realm Japan meetup #11

Realm Japan meetup #11

Realmのアーキテクチャ
- 遅延ロード・ゼロコピーの図解
- クエリがどのように実行されるか

Kishikawa Katsumi

July 24, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. class Article: Object { dynamic var id: Int = 0

    dynamic var title: String = "" dynamic var content: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var deletionDate: NSDate? = nil dynamic var user: User? = nil let comments = List<Comment>() override static func primaryKey() -> String? { return "id" } } class Comment: Object { dynamic var id: Int = 0 dynamic var content: String = "" dynamic var user: User? = nil override static func primaryKey() -> String? { return "id" } } class User: Object { dynamic var id: Int = 0 dynamic var name: String = "" override static func primaryKey() -> String? { return "id" } }
  2. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser try! realm.write { in realm.add(article) }
  3. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) try! realm.write { in currentUser.name = "..." }
  4. override func viewDidLoad() { ... articles = realm.objects(Article).filter("user = %@",

    currentUser) } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return articles.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("", forIndexPath: indexPath) let article = articles[indexPath.row] cell.title = article.title cell.content = article.content cell.username = article.user.name return cell }
  5. ඇಉظΫΤϦ (Swift) let allArticles = realm.objects(Article) let articles = allArticles.filter(“user

    = %@", currentUser) 3FTVMUT"SUJDMF 5BCMF"SUJDMF 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS
  6. ඇಉظΫΤϦ (Swift) let articles = allArticles.filter(“user = %@", currentUser) let

    count = articles.count 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX
  7. ඇಉظΫΤϦ (Swift) let count = articles.count let article = articles[0]

    3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX "SUJDMF 3PX*OEFY 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX
  8. ඇಉظΫΤϦ (Swift) let article = articles[0] let title = article.title

    "SUJDMF 3PX*OEFY 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX "SUJDMF 3PX*OEFY 5JUMF(FUUFS 3FBMN 4USJOH 5JUMF
  9. Where to find us • # Realm Japan User Group:

    facebook.com/groups/realmjp • # Twitter: twitter.com/realmJapan • GitHub: github.com/realm • # StackOverflow: ja.stackoverflow.com/questions/tagged/realm • # Email: [email protected] • # Slack: slack.realm.io/