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

Realm on 英単語サプリ

Realm on 英単語サプリ

5月のRealmミートアップで発表した資料です

Reo Yoshida

July 03, 2015
Tweet

Other Decks in Technology

Transcript

  1. 3FBMN͕࠷ߴͳཧ༝
 ᶃɿͱͯ΋γϯϓϧ w Ϟσϧͷ௥Ճ͸3-.0CKFDUΛܧঝͨ͠ΫϥεΛ࡞Δ͚ͩ ˞WFSܥΛ࢖༻ import Foundation import Realm class

    Person: RLMObject { dynamic var name:String? } let person = Person() person.name = "Yoshida" let realm = RLMRealm.defaultRealm() realm.beginWriteTransaction() realm.addObject(person) realm.commitWriteTransaction()
  2. 3FBMN͕࠷ߴͳཧ༝
 ᶃɿͱͯ΋γϯϓϧ w ϦϨʔγϣϯΛషΔͷ΋εΰΠ؆୯  ˞WFSܥΛ࢖༻ import Foundation import Realm

    class Person: RLMObject { dynamic var name:String? dynamic var dog:Dog? } let person = Person() person.name = "Yoshida" let dog = Dog() dog.name = "John" person.dog = dog let realm = RLMRealm.defaultRealm() realm.beginWriteTransaction() realm.addObject(person) realm.commitWriteTransaction()
  3. 3FBMN͕࠷ߴͳཧ༝
 ᶃɿͱͯ΋γϯϓϧ w ϦϨʔγϣϯΛషΔͷ΋εΰΠ؆୯ ଟ ˞WFSܥΛ࢖༻ import Foundation import Realm

    class Person: RLMObject { dynamic var name:String? dynamic var dogs:RLMArray(objectClassName: Dog.className()) } let person = Person() person.name = “Yoshida" let dog = Dog() dog.name = "John" let dog2 = Dog() dog2.name = "John2" person.dogs.addObjects([dog, dog2]) let realm = RLMRealm.defaultRealm() realm.beginWriteTransaction() realm.addObject(person) realm.commitWriteTransaction()
  4. ˞WFSܥΛ࢖༻ ͜Μͳίʔυॻ͍ͨ࣌ʹࠔͬͨ Downloader.downloadPersonalInfo(person) class Downloader: NSObject { class func downloadPersonalInfo(person:

    Person) { let req = NSURLRequest() NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue()) { (resp, data, error) -> Void in /* DataऔΓग़͠ */ person.info = downloadedInfo } } }
  5. ˞WFSܥΛ࢖༻ ղܾࡦ Downloader.downloadPersonalInfo(person) class Downloader: NSObject { class func downloadPersonalInfo(personID:

    String) { let req = NSURLRequest() NSURLConnection.sendAsynchronousRequest(req, queue: NSOperationQueue()) { (resp, data, error) -> Void in /* DataऔΓग़͠ */ let person = Person(forPrimaryKey: personID) person.info = info } } }