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

Realm Japan meetup #8

Realm Japan meetup #8

Realm Objective-C/Swift 0.96
- Null support
- Collection Keypath query
- Improve error handling

Realm Java 0.84
- Null support
- Async queary

Kishikawa Katsumi

October 28, 2015
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. Realm Java 0.83.0 w /6--ϓϩύςΟ w ৽͍͠ϑΝΠϧϑΥʔϚοτ w ཁϚΠάϨʔγϣϯʢ·ͨ͸!3FRVJSFEΞϊςʔγϣϯʣ w

    ϓϦϛςΟϒϥούʔΫϥεͷαϙʔτ *OUFHFS -POH ʜ  w OVMMʹର͢ΔΫΤϦ w ूܭʢBWFSBHFɺTVNɺNBYͳͲʣͷมߋ w Y@αϙʔτ w %BUFܕ͕දݱͰ͖Δൣғͷ֦େ ਫ਼౓͸ඵͷ··
  2. NULLϓϩύςΟ (Java) class User extends RealmObject { @PrimaryKey int id;

    @Required String name; Date birthday; // Nullable Integer age; // Nullable }
  3. Ξοϓσʔτ͢ΔͱMigration͕ඞཁʹͳΓ·͢ class User extends RealmObject { @Required // <= ௥Ճ

    String name; } // ·ͨ͸ Table userTable = realm.getTable(User.class);
 long nameIndex = userTable.getColumnIndex("name");
 userTable.convertColumnToNullable(nameIndex); !3FRVJSFEΛࢦఆɺ΋͘͠͸ϚΠάϨʔγϣϯॲཧ
  4. Realm Java 0.84.0 w ඇಉظΫΤϦɾτϥϯβΫγϣϯ w ࣌ؒͷ͔͔ΔΫΤϦ΍ॻ͖ࠐΈΛόοΫάϥ΢ϯυͰߦ͏ w JT&NQUZ ɺEJTUJODU

     w ۭจࣈɺۭϦετʢ/6--Ͱͳ͍ʣͷ൑ఆͱɺॏෳΛআ͘ w JT$MPTFE ɺJT*O5SBOTBDUJPO ɺJT7BMJE  w ૢ࡞ͷલʹ3FBMN΍ΦϒδΣΫτͷঢ়ଶ͕Θ͔ΔΑ͏ʹ w 3FBMN1SJNBSZ,FZ$POTUSBJOU&YDFQUJPOͷಋೖ
  5. ඇಉظΫΤϦ RealmResults<User> result = realm.where(User.class) .contains("name", searchText) .findAllAsync(); result.addChangeListener( new

    RealmChangeListener() { @Override public void onChange() { // ΫΤϦ׬ྃޙɺߋ৽͕͋Δͨͼʹݺͼग़͞Ε·͢ɻ } }); // onStop() ౳Ͱొ࿥ղআΛ๨Εͣʹ result.removeChangeListeners(); // ొ࿥͞Ε͍ͯΔશͯͷϦεφͷొ࿥Λղআ
  6. ඇಉظτϥϯβΫγϣϯ realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm bgRealm) {

    // ͜͜ʹߋ৽ॲཧΛهड़ } }, new Realm.Transaction.Callback() { @Override public void onSuccess() { // commit ͕׬ྃͨ࣌͠ } @Override public void onError(Exception e) { // Τϥʔ͕ൃੜͯ͠τϥϯβΫγϣϯ͕ϩʔϧόοΫ͞Εͨ࣌ } });
  7. ։ൃத w 3Y+BWBରԠ w IUUQTHJUIVCDPNSFBMNSFBMNKBWBQVMM w IUUQTHJUIVCDPNSFBMNSFBMNKBWBJTTVFT w /FX.JHSBUJPO"1* w

    IUUQTHJUIVCDPNSFBMNSFBMNKBWBQVMM w IUUQTHJUIVCDPNSFBMNSFBMNKBWBQVMM
  8. Realm Objective-C/Swift 0.96.0 w /6--ϓϩύςΟ w ৽͍͠ϑΝΠϧϑΥʔϚοτ w ཁϚΠάϨʔγϣϯʢ·ͨ͸ SFRVJSFE1SPQFSUJFTʣ

    w ΩʔύεɾίϨΫγϣϯɾΫΤϦ w SFBMNPCKFDUT "SUJDMF pMUFS DPNNFOUT!DPVOU  w ΤϥʔϋϯυϦϯάͷվળ w ίϛοτ࣌ͷΤϥʔΛΩϟονͯ͠෮ؼͰ͖ΔΑ͏ʹ
  9. NULLϓϩύςΟ (Swift) class User: Object { dynamic var id =

    0 dynamic var name = "" dynamic var birthday: NSDate? // Nullable let age = RealmOptional<Int>(0) // Nullable override static func primaryKey() -> String? { return "id" } }
  10. NULLϓϩύςΟ (Objective-C) @interface User : RLMObject @property NSInteger identifier; @property

    NSString *name; @property NSDate *birthday; // Nullable @property NSNumber<RLMInt> *age; // Nullable @end @implementation User + (NSString *)primaryKey { return @"identifier"; } + (NSArray *)requiredProperties { return @[@"name"]; } @end
  11. Ξοϓσʔτ͢ΔͱMigration͕ඞཁʹͳΓ·͢ Migration is required for object type 'User' due to

    the following errors: - Property 'birthday' has been made optional. - Property 'name' has been made optional.
  12. Ξοϓσʔτ͢ΔͱMigration͕ඞཁʹͳΓ·͢ Migration is required for object type 'User' due to

    the following errors: - Property 'birthday' has been made optional. - Property 'name' has been made optional. SFRVJSFE1SPQFSUJFTΛࢦఆ͢Δ͔ɺϚΠάϨʔγϣϯॲཧΛ ॻ͖·͢ɻ
  13. ίϨΫγϣϯɾΩʔύεɾΫΤϦ class Comment: Object { dynamic var id = 0

    dynamic var user: User dynamic var text = "" } class Article: Object { dynamic var id = 0 dynamic var title = "" dynamic var text = "" let comments = List<Comment>() } let articles = realm.objects(Article).filter("comments.@count > 0")
  14. 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/