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

Realm を正しく使うには

Be1eb78c61dbd72bf1eec446cefef2b1?s=47 numa08
September 29, 2015

Realm を正しく使うには

Android で Realm を使う際の気をつける点とかを共有@ #realm_jp

Be1eb78c61dbd72bf1eec446cefef2b1?s=128

numa08

September 29, 2015
Tweet

Transcript

  1. 3FBMNΛ ਖ਼͘͠࢖͏ʹ͸ "OESPJEฤ !OVNB SFBMN@KQ

  2. !OVNB  IUUQOVNBIBUFCMPKQ

  3. DPWFMMJOF --$  GFBUIFSܰշͳUXJUUFSΫϥΠΞϯτ

  4. 3FBMNΛਖ਼͘͠࢖͏ʹ͸  3FBMN͸ߴ଎ͳ%#.4Ͱ͋Δ 3FBMN͸ଞͷ%#.4ͱൺֱͯ͠ѹ౗తʹߴ଎Ͱ͋Δɻ ͔͠͠ɺଞͷ%#.4ʹ͸ແ੍͍໿΍஫ҙ఺͕͋Δɻ εϨουؒ௨৴ɺίϯϙʔωϯτؒ௨৴ɺςετFUDʜ "OESPJEͰ3FBMNΛ࢖ͬͨ࿩ͷ঺հ UXJUUFSΫϥΠΞϯτGFBUIFSͰ3FBMNΛ࢖ͬͨɻ πΠʔτͷಡΈࠐΈɺදࣔؔ࿈ʹ͍ͭͯϋϚͬͨ఺Λ঺հɻ

  5. ΞδΣϯμ  ઃܭ w ࠓͷઃܭ w ੲͷઃܭ w ੲͷઃܭͷࣦഊ఺ ςετ

    w ςετͷ5JQT
  6. ࠓͷઃܭ 

  7. ੲͷઃܭ 

  8. πΠʔτͷ؅ཧΦϒδΣΫτ  ࠓ ੲ class Tweet extends RealmObject { String

    text; Date createAt; String userName; public Tweet(){} public Tweet(String text, Date createAt, String userName) { this.text = text; this.createAt = createAt; this.userName = userName; } } class Tweet implements Content { String text; Date createAt; String userName; // RealmTweet extends RealmObject public Tweet(RealmTweet obj){ this.text = obj.getText(); this.createAt = obj.getCreateAt(); this.userName = obj.getUserName(); } }
  9. ੲͷઃܭ  ޓ׵ੑ͕ཉ͔ͬͨ͠ 3FBMNҎ֎ͷ%#.4΍03.ͷ࠾༻΋ݕ౼͍ͯͨ͠ɻ ͍ͭͰ΋৐Γ׵͑ΒΕΔΑ͏ʹɺޓ׵ੑΛҙ͍ࣝͯͨ͠ɻ

  10. ੲͷઃܭͷμϝͳ఺  ϝϞϦ࢖͍͗͢໰୊ ͔ͳΓେྔͷΦϒδΣΫτΛϝϞϦ্ʹల։͢ΔͷͰɺ ޻෉͕ٻΊΒΕͨɻ 3FBMNͷϝϦοτΛ׆͔ͤͯͳ͍໰୊ ಠࣗΦϒδΣΫτͷల։ʹΑͬͯɺಈ࡞͕஗͘ͳͬͨɻ ஗Ԇϩʔυ΍($Λར༻͠ͳ͍ͷͰɺແҙຯͳϝϞϦফඅʹܨ͕ͬͨɻ ޓ׵ੑΛࣺͯͯ3FBMNΛ࢖͏ํࣜʹํ޲స׵

  11. εϨουؒ௨৴  ੲ ࠓ ಡΈࠐΈ όοΫάϥ΢ϯυͰ࣮ߦ ॻ͖ࠐΈ όοΫάϥ΢ϯυͰ࣮ߦ εϨουؒ௨৴ ಠࣗΦϒδΣΫτʹల։

    ಡΈࠐΈ 6*εϨουͰ࣮ߦ ॻ͖ࠐΈ όοΫάϥ΢ϯυͰ࣮ߦ εϨουؒ௨৴ ࣝผࢠɺΫΤϦΛ΍ΓͱΓɻ ࣍ͷεϨουͰΫΤϦΛ࣮ߦɻ
  12. ίϯϙʔωϯτؒ௨৴  ੲ ࠓ ίϯϙʔωϯτؒ௨৴ ಠࣗͷ1BSDFMBCMFͳΦϒδΣΫτʹ ల։ ίϯϙʔωϯτؒ௨৴ ࣝผࢠɺΫΤϦΛ΍ΓͱΓɻ ࣍ͷίϯϙʔωϯτͰΫΤϦ࣮ߦɻ

  13. ςετͷ࿩  ઃܭ w +7.Ͱ͸ςετ͕Ͱ͖ͳ͍ w ϑΝΠϧ࡟আ࣌ͷ஫ҙࣄ߲ w 6*εϨουςετͷ஫ҙࣄ߲ εϨουؒ௨৴ɺίϯϙʔωϯτؒ௨৴ͷ੍ݶ΋͋ͬͯɺςετ࣮ߦ΋஫ҙ͕ඞཁ

    ͱͳΔɻ
  14. ςετͷ࿩  +7.্Ͱ͸ςετ͕Ͱ͖ͳ͍ +7.্ͷςετͰ͸ωΟςΟϒϥΠϒϥϦ͕ಡΈࠐΊͳ͍ͷͰɺ3FBMNΠϯελϯ ε΁ΞΫηεͰ͖ͳ͍ɻ *OTUSVNFOUBUJPO5FTUͰ͋Δඞཁ͕͋Δɻ ิ଍ɹ 3FBMN0CKFDUͷαϒΫϥεΛΠϯελϯεԽ͢Δͷ͸ɺ+7.্Ͱ΋Մೳɻ ίϯετϥΫλͷςετ΍ɺ3FBMN΁ͷಡΈॻ͖ͷແ͍ςετͳΒେৎ෉ɻ

  15. ςετͷ࿩  ϑΝΠϧ࡟আ࣌ͷ஫ҙࣄ߲ 3FBMNͷ%#ϑΝΠϧ͸શͯͷίωΫγϣϯ͕DMPTF͞Ε͍ͯͳ͍ͱ࡟আͰ͖ͣɺ ྫ֎͕ඈͿɻ !"GUFSͰ࡟আΛ͢Δ৔߹ʹɺ࣮֬ʹDMPTF͕ݺ͹ΕΔΑ͏ʹ͢Δඞཁ͕͋Δɻ ςετʹࣦഊͯ͠DMPTF͠๨Εͯ!"GUFS͕ݺ͹ΕΔͱྫ֎͕ݟ೉͘ͳΔɻ w ςετϝιουͰUSZpOBMMZ USZXJUISFTPVSDFT

    Λ࢖ͬͯDMPTF͢Δ w !"GUFSͰDMPTF͔ͯ͠Β࡟আΛ͢Δ
  16. ςετͷ࿩  !6*5ISFBE5FTUͷ஫ҙ఺ !6*5ISFBE5FTU͸!#FGPSF !"GUFSͱ͸ҧ͏εϨουͰ࣮ߦ͞ΕΔɻ ͦͷͨΊɺ3FBMNΠϯελϯεͳͲ͸ɺςετϝιου಺Ͱ༻ҙɺ ࡟আ͢Δඞཁ͕͋Δɻ