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

Realm Xamarin

Realm Xamarin

USAMI Kosuke

June 22, 2016
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. Xamarin » C# Ͱ iOS / Android ωΠςΟϒΞϓϦ։ൃ » iOS

    / Android ͰίʔυΛڞ༗Մೳ » .NET ϥΠϒϥϦ / ωΠςΟϒϥΠϒϥϦΛ࢖༻Մೳ
  2. Realm » ϞόΠϧΞϓϦ޲͚σʔλϕʔε » Objective-C / Swift / Java /

    React Native / Xamarin » ࢖͍΍͘͢ɺύϑΥʔϚϯε΋༏ल
  3. Realm 1.0 » Objective-C / Swift / Java ͕ beta

    ͔Β 1.0 ΁ » beta Ͱͳ͘ͳͬͨ͜ͱͰɺಋೖͷෑډ͕௿͘ͳͬͨ » React Native / Xamarin ͸ beta ʢ·ͩొ৔ͨ͠͹͔Γʣ
  4. Model public class Person : RealmObject { public string Name

    { get; set; } public int Age { get; set; } }
  5. getter / setter ͷࣗಈੜ੒ » ࣗಈ࣮૷ϓϩύςΟ͸ɺgetter ͱ setter ͕ࣗಈੜ੒͞ΕΔ »

    ͦͷதͰ Realm ಺෦ετϨʔδͱؔ࿈෇͚͞ΕΔ » Ignore ଐੑΛ͚ͭΔͱࣗಈੜ੒͞Εͳ͍ » ΧελϜ getter / setter ͸্ॻ͖͞Εͳ͍
  6. ΦϒδΣΫτͷऔಘʢΫΤϦʣ public IEnumerable<Person> Persons { get; private set; } public

    PersonViewModel() { var realm = Realm.GetInstance(); Persons = realm.All<Person>() }
  7. ΦϒδΣΫτͷ௥Ճ public AddPerson() { var realm = Realm.GetInstance(); using(var transaction

    = realm.BeginWrite()) { var person = realm.CreateObject<Person>(); person.Name = "Hoge"; person.Age = 20; transaction.Commit(); } // ࣗಈతʹ transaction ͕ Dispose() ͞ΕΔ }
  8. ΦϒδΣΫτͷࣗಈߋ৽ ʢઌ΄ͲͷίʔυΛ࠶ܝʣ public PersonViewModel() { var realm = Realm.GetInstance(); Persons

    = realm.All<Person>() // ΦϒδΣΫτΛ௥Ճͨ͠ΒɺPersons ͕ࣗಈతʹߋ৽͞ΕΔ // ࠶౓ All ΫΤϦΛ࣮ߦ͢Δඞཁ͸ͳ͍ }
  9. LINQ ʹΑΔΫΤϦ // ϝιουߏจ Persons = realm.All<Person>() .Where(p => p.Age

    < 20); // ΫΤϦࣜ Persons = from p in realm.All<Person>() where p.Age < 20 select p;
  10. Realm Xamarin ·ͱΊ » ͱͯ΋؆୯ʹ࢖͑Δ » C# ͱͯࣗ͠વʹॻ͚Δ » ࢀߟࢿྉ

    » Realm Xamarin https://realm.io/jp/docs/xamarin/latest/ » Cross-Platform Development with Xamarin.Forms and Realm | Xamarin Blog