$30 off During Our Annual Pro Sale. View details »

Realm使ってみた (SWWDC 仙台iPhoneとか開発者勉強会 その26)

tototti
February 02, 2016

Realm使ってみた (SWWDC 仙台iPhoneとか開発者勉強会 その26)

2016/01/30 SWWDC 仙台iPhoneとか開発者勉強会 その26 - 新春ライトニングトーク大会 -

tototti

February 02, 2016
Tweet

More Decks by tototti

Other Decks in Programming

Transcript

  1. 3FBMN࢖ͬͯΈͨ 488%$ !UPUPUUJ

  2. ಡΈํ͸ϨϧϜ

  3. 3FBMN w NPCJMF޲͚ͷσʔλϕʔε w 42-JUFͷ୅ସΛ໨ࢦ͍ͯ͠ΔΒ͍͠ w 3FMBUJPOBMͰ͸ͳ͘ɺ,74Β͍͠ ˞ Ͳ͔ͬʹॻ͍͚ͯ͋ͬͨͲɺ ະ֬ೝ

    ɾТɾA
  4. ࢖ͬͯΈͨ w ʮઋ୆ϏʔϧϚοϓʯΞϓϦ w ళฮνΣοΫΠϯػೳ

  5. Πϯετʔϧ w QPEl3FBMN w QPEJOTUBMM

  6. ςʔϒϧఆٛ w ΫϥεΛॻ͚ͩ͘ͰPL @interface Visit : RLMObject @property NSString* shopID;

    @property NSDate* visitDate; @property NSString* memo; @property NSData* imageData; @end 4XJGU0CK$ࠞࡏϓϩδΣΫτͷ৔߹ɺ 0CK$Ͱॻ͘΄͏͕ྑ͍Β͍͠ ŖAшŖ /4%BUF /4%BUB΋ ͦͷ··Ϳͬ͜ΊΔ
  7. JOTFSUEFMFUF RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; [realm addObject:visit];

    [realm commitWriteTransaction]; RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; [realm deleteObject:visit]; [realm commitWriteTransaction];
  8. VQEBUF w ࠓճ͸࢖Θͳ͔͕ͬͨʜ w ςʔϒϧʹϓϥΠϚϦΩʔΛࢦఆ͢Δ // addOrUpdateObjectͰupdate realm.beginWriteTransaction() realm.addOrUpdateObject(visit) realm.commitWriteTransaction()

  9. 4FMFDU // શऔಘ RLMResults<Visit *> *visits = [Visit allObjects]; //

    શऔಘ + ιʔτ NSArray* sortProperties = @[[RLMSortDescriptor sortDescriptorWithProperty:@"visitDate" ascending:NO]]; RLMResults<Visit *> *visits = [[Visit allObjects] sortedResultsUsingDescriptors:sortProperties]; // ৚݅ࢦఆ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"shopID = %@", shopID]; RLMResults<Visit *> *visits = [Visit objectsWithPredicate:predicate];
  10. ͜Ε͸շదʜ

  11. ·ͱΊ w ଎౓΋଎͍Β͍͠ w ͱʹָ͔͘ɻ w ςʔϒϧ࡞੒ w JOTFSUEFMFUFTFMFDU w

    খ͍͞σʔλͰ΋ɺQMJTUอଘ͢ΔΑΓ΋ָ