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

OSC Tokushima 2015 Realm

OSC Tokushima 2015 Realm

9bf923e39671cde83584e3e926296c13?s=128

Kishikawa Katsumi

November 14, 2015
Tweet

Transcript

  1. 劤傈ךأٓ؎س IUUQCJUMZPTDSFBMN

  2. 如⚅➿.PCJMFر٦ةك٦أ 3FBMN

  3. IUUQTHJUIVCDPNLJTIJLBXBLBUTVNJ LJTIJLBXBLBUTVNJ IUUQCMPHLJTIJLBXBLBUTVNJDPN 3FBMN 5FDIOJDBM"EWJTPS 3FBMN*OD

  4. 3FBMNהכ⡦ַ

  5. ٌغ؎ٕرغ؎أ㼔欽ח倜׃ֻ⡲׵׸׋ر٦ةك٦أ ٌغ؎ٕ欽鷿ח剑黝⻉ׁ׸גְ׷  鹼䒀ٗ٦س  ئٗ؝ؾ٦٥،٦ؗذؙثٍ  ط؎ذ؍ـ٥ؙٔٝ 杝荈ؒٝآٝ42-JUF׾⢪׏גְזְ ؔ٦فٝا٦أ

     ぐ珏غ؎ٝر؍ؚٝ0CKDUJWF$4XJGU+BWBⰕꟚ׆׫  ⰻ鿇أزٖ٦آؒٝآٝת׮זֻⰕꟚ✮㹀 3FBMNהכ⡦ַ
  6. 3FBMNِ٦ؠ٦

  7. 3FBMNָ⢪׻׸גְ׷،فٔ 傈劤穗幥倜耀ꨵ㶨晛 1JOUFSFTU $BNFSBO "8" 薉⽃铂؟فٔ 4ZODCZ8BOUFEMZ $IBUXPSL (SPVQPO GFBUIFSGPS5XJUUFS

    5XJUQBOF 'BMDPO1SP "QMPT J$PNJDT &JHIUCZ4BOTBO
  8. 넝鸞ז⹛⡲ 农〾⻉׾垥彊鄲⪒ وٕثفٓحزؿؓ٦ي J04049"OESPJE +4/&5BSFDPNJOH  湫䠬涸דءٝفٕז"1* ♨㻝ז؟ه٦ز傈劤铂0, 3FBMNך暴ꞿ

  9. class Article: Object { dynamic var id: Int = 0

    dynamic var title: String = "" dynamic var contents: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var deletionDate: NSDate? = nil dynamic var user: User? = nil let comments = List<Comment>() } وٕثفٓحزؿؓ٦ي J04
  10. public class Article extends RealmObject { @PrimaryKey private int id;

    private String title; private String contents; private Date creationDate; private Date modificationDate; private Date deletionDate; private User user; private RealmList<Comment> user; } وٕثفٓحزؿؓ٦ي "OESPJE
  11. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text realm.write { () in realm.add(article) } وٕثفٓحزؿؓ٦ي J04
  12. Realm realm = Realm.getInstance(this); realm.beginTransaction(); Article article = realm.createObject(Article.class); article.setText(titleTextfield.getText());

    article.setContents(contentTextfield.getText()); realm.commitTransaction(); وٕثفٓحزؿؓ٦ي "OESPJE
  13. J04"OESPJE⚕倯ד3FBMNָ⢪׻׸גְ׷،فٔ "8" &JHIUCZ4BOTBO 㹺做،ٕغي׫גי J20/

  14. 傀㶷ך03.ך妀挿׾縧ֹ䳔ִ׷׋׭ 搀꼽ז䬄韋⻉׾鼘ֽ׷ ػؿؓ٦وٝأךؔ٦غ٦قحس׾搀ֻׅ ז׈أؙٓحثדַ׵Ꟛ涪׃׋ַ

  15. None
  16. 㛇劤涸ז⢪ְ倯

  17. 㛇劤涸ז⢪ְ倯 إحز،حف

  18. J04049  8FC؟؎زַ׵تؐٝٗ٦س  $PDPB1PET׾ⵃ欽ׅ׷  $BSUIBHF׾ⵃ欽ׅ׷ "OESPJE  8FC؟؎زַ׵تؐٝٗ٦س

     (SBEMF IUUQTSFBMNJPKQ إحز،حف
  19. إحز،حف 8FC؟؎زַ׵تؐٝٗ٦س

  20. 8FC؟؎زַ׵تؐٝٗ٦س

  21. 8FC؟؎زַ׵تؐٝٗ٦س

  22. 8FC؟؎زַ׵تؐٝٗ٦س

  23. 8FC؟؎زַ׵تؐٝٗ٦س

  24. &NCFEEFE#JOBSJFTחسٓحؚسٗحف

  25. &NCFEEFE#JOBSJFTחسٓحؚسٗحف

  26. 3VO4DSJQU1IBTF׾鷄⸇

  27. bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/ Realm.framework/strip-frameworks.sh"׾鷄⸇

  28. إحز،حف $PDPB1PET׾ⵃ欽

  29. platform :ios, '8.0' use_frameworks! target 'SchooApp' do pod 'RealmSwift' end

    1PEMF׾⡲䧭ׅ׷
  30. $ pod install Updating local specs repositories Analyzing dependencies Downloading

    dependencies Installing Realm (0.93.2) Installing RealmSwift (0.93.2) Generating Pods project Integrating client project [!] Please close any current Xcode sessions and use `SchooApp.xcworkspace` for this project from now on. Sending stats $ pod install Λ࣮ߦ͢Δ
  31. 㛇劤涸ז⢪ְ倯 ٌرٕך㹀纏ծر٦ةך⥂㶷٥嗚稊٥刿倜

  32. 㛇劤涸ז⢪ְ倯 ٌرٕך㹀纏

  33. ٌرٕך㹀纏

  34. import RealmSwift class Article: Object { dynamic var id: Int

    = 0 dynamic var title: String = "" dynamic var contents: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var deletionDate: NSDate? = nil dynamic var user: User? = nil let comments = List<Comment>() } class Comment: Object { dynamic var id: Int = 0 dynamic var contents: String = "" dynamic var user: User? = nil } class User: Object { dynamic var id: Int = 0 dynamic var name: String = "" } ٌرٕך㹀纏
  35. import RealmSwift class Article: Object { dynamic var id: Int

    = 0 dynamic var title: String = "" dynamic var contents: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var deletionDate: NSDate? = nil dynamic var user: User? = nil let comments = List<Comment>() } class Comment: Object { dynamic var id: Int = 0 dynamic var contents: String = "" dynamic var user: User? = nil } class User: Object { dynamic var id: Int = 0 dynamic var name: String = "" } ٌرٕך㹀纏
  36. ٌرؙٕٓأכ0CKFDU ת׋כ3-.0CKFDU ׾竰䪫ׅ׷䗳銲ָ֮׷ ؙٓأ׾㹀纏ׅ׸ל荈⹛涸חأؗ٦وָ㹀纏ׁ׸׷ 䪔ִ׷ر٦ة㘗כ⟃♴ך鸐׶ 4USJOH /44USJOH /4%BUF /4%BUB ぐ珏*OU

    'MPBU %PVCMF ׅץגךر٦ة㘗חאְג/6--〳♶〳ך⼒ⴽָדֹ׷ ٌرٕך㹀纏
  37. 㛇劤涸ז⢪ְ倯 ٌرٕך㹀纏 ⿫罋$PSF%BUBהך嫰鯰

  38. ٌرٕך㹀纏$PSF%BUB

  39. import CoreData class Article: NSManagedObject { @NSManaged var id: NSNumber

    @NSManaged var title: String @NSManaged var contents: String @NSManaged var creationDate: NSDate @NSManaged var modificationDate: NSDate @NSManaged var deletionDate: NSDate? @NSManaged var user: User @NSManaged var comments: NSSet? } class User: NSManagedObject { @NSManaged var id: NSNumber @NSManaged var name: String } class Comment: NSManagedObject { @NSManaged var id: NSNumber @NSManaged var contents: String @NSManaged var user: User } ٌرٕך㹀纏$PSF%BUB
  40. 㛇劤涸ז⢪ְ倯 ٌرٕך㹀纏 ⿫罋42-JUFהך嫰鯰

  41. CREATE TABLE IF NOT EXISTS article ( id INTEGER, title

    TEXT, contents TEXT, creationCate DATE, modificationCate DATE, deletionCate DATE ) CREATE TABLE IF NOT EXISTS user ( id INTEGER, name TEXT ) CREATE TABLE IF NOT EXISTS comment ( id INTEGER, contents TEXT, ) ٌرٕך㹀纏42-JUF
  42. 㛇劤涸ז⢪ְ倯 ر٦ةך⥂㶷

  43. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser try! realm.write { in realm.add(article) } ⥂㶷
  44. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser try! realm.write { in realm.add(article) } ⥂㶷3FBMN؎ٝأةٝأ׾《䖤
  45. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser try! realm.write { in realm.add(article) } ⥂㶷ؔـآؙؑز׾欰䧭
  46. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser try! realm.write { in realm.add(article) } ⥂㶷ꟼ鸬ؔـآؙؑز׾《䖤
  47. let realm = try! Realm() let article = Article() article.title

    = titleTextfield.text article.contents = contentTextfield.text let currentUser = realm.objectForPrimaryKey(User.self, key: userID) article.user = currentUser realm.write { () in realm.add(article) } ⥂㶷ر؍أؙח剅ֹ鴥׬
  48. 㛇劤涸ז⢪ְ倯 ⥂㶷 ⿫罋$PSF%BUBהך嫰鯰

  49. let article = NSEntityDescription .insertNewObjectForEntityForName("Article", inManagedObjectContext: managedObjectContext) article.title = titleTextfield.text

    article.contents = contentTextfield.text let fetchRequest = NSFetchRequest(entityName: "User") fetchRequest.predicate = NSPredicate(format: "id = %@", userID) if let currentUser = managedObjectContext.executeFetchRequest(fetchRequest).first { article.user = currentUser } managedObjectContext.save() ⥂㶷$PSF%BUB
  50. lazy var managedObjectModel: NSManagedObjectModel = { let modelURL = NSBundle.mainBundle().URLForResource("Data",

    withExtension: "momd")! return NSManagedObjectModel(contentsOfURL: modelURL)! }() lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = { let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("Data.sqlite") var failureReason = "There was an error creating or loading the application's saved data." do { try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil) } catch { abort() } return coordinator }() lazy var managedObjectContext: NSManagedObjectContext = { let coordinator = self.persistentStoreCoordinator var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) managedObjectContext.persistentStoreCoordinator = coordinator return managedObjectContext }() /4.BOBHFE0CKFDU$POUFYUך《䖤$PSF%BUB
  51. 㛇劤涸ז⢪ְ倯 ر٦ةך嗚稊

  52. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article).filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 嗚稊
  53. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article).filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 嗚稊فٓ؎ؤؗ٦ד嗚稊
  54. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article).filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 嗚稊勴⟝ד嗚稊
  55. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article).filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 嗚稊6*׾刿倜
  56. 㛇劤涸ז⢪ְ倯 ر٦ةך刿倜

  57. let comment = Comment() ... try! realm.write { in article.comments.append(comment)

    } 刿倜
  58. let comment = realm.objectForPrimaryKey(Comment.self, key: commentID) ... try! realm.write {

    in realm.comments.removeAtIndex(realm.comments.indexOf(comment)) realm.delete(comment) } ⵴ꤐ
  59. 3FBMNך➬穈׫

  60. 䗡䎿׃׋鹼䒀ٗ٦س

  61. 颩ְغ؎ٝر؍ؚٝ堣圓ח״׷䗡䎿׃׋鹼䒀ٗ٦س فٗػذ؍ח،ؙإأׅ׷תדְַז׷ر٦ة׮⥂䭯׃זְ 㣐ꆀךر٦ة侧⼧ծ侧涰♰⟝ד׮넝鸞ח満ًٌٔד⸬桦״ֻ䪔ִ׷ 䗡䎿׃׋鹼䒀ٗ٦س

  62. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article).filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 䗡䎿׃׋鹼䒀ٗ٦س
  63. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article) .filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name 䗡䎿׃׋鹼䒀ٗ٦س 㹋ꥷךر٦ةכ《䖤ׁ׸זְ 㹋ꥷךر٦ةכ《䖤ׁ׸זְ 㹋ꥷךر٦ةכ《䖤ׁ׸זְ UJUMFؕٓيךر٦ةչ׌ֽպ《䖤
  64. 3FBMN ׉ך➭ך03. 㹋ꥷח،ؙإأׅ׷鿇ⴓ ׌ֽر٦ة׾铣׫⳿ׅ ⟝侧ⴓך ؔـآؙؑز ָ⡲׵׸׷

  65. ئٗ٥؝ؾ٦ ر٦ة׾♧ⴖ؝ؾ٦׃זְ

  66. .FNPSZNBQQFEؿ؋؎ٕ ًٌٔהر؍أؙ♳דずׄؿؓ٦وحزךر٦ة ر٦ةךؔؿإحز׾⥂䭯 فٗػذ؍ך،ؙإأדⴱ׭גر٦ة׾《䖤 ئٗ٥؝ؾ٦

  67. let realm = try! Realm() let currentUser = realm.objectForPrimaryKey(User.self, key:

    userID) let articles = realm.objects(Article) .filter("user = %@", currentUser) let article = articles[indexPath.row] cell.titleTextLabel.text = article.title cell.contentTextLabel.text = article.contents cell.userNameLabel.text = article.user.name ئٗ٥؝ؾ٦ 㹋ꥷךر٦ةכ《䖤ׁ׸זְ 㹋ꥷךر٦ةכ《䖤ׁ׸זְ 㹋ꥷךر٦ةכ《䖤ׁ׸זְ UJUMFؕٓيךر٦ةչ׌ֽպ《䖤
  68. .7$$"SDIJUFDUVSF .VMUJ7FSTJPO$PODVSSFODZ$POUSPM

  69. .VMUJ7FSTJPO$PODVSSFODZ$POUSPM غ٦آّٝ㾶娖ח״׷زٓٝؠؙءّٝך盖椚 ぐزٓٝؠؙءّٝכծ֮׷儗挿ךأشحفءّحز 铣׫鴥׫כⴽך铣׫鴥׫ծ剅ֹ鴥׫׾ـٗحؙ׃זְ 剅ֹ鴥׫כ铣׫鴥׫׾ـٗحؙ׃זְ 剅ֹ鴥׫ה剅ֹ鴥׫כـٗحؙׅ׷ .7$$"SDIJUFDUVSF

  70. ꟼ鸬ך؝أزָ㸜ְ ط؎ذ؍ـ٥ؙٔٝ

  71. 3FBMNךر٦ة圓鸡כ䊬㣐ז# USFF 㼎ծ㼎㢳ךꟼ鸬׾荈搫ח邌植דֹ׷ ه؎ٝة׾籬ּ׌ֽծ؝أزך넝ְ+PJOכ♶銲 6*ך鿪さחさ׻ׇגر٦ة圓鸡׾㹀纏׃װְׅ ꟼ鸬ך؝أزָ㸜ְ

  72. ➙䖓؟ه٦زׁ׸׷堣腉

  73. 刿倜װ⵴ꤐךⰻ㺁ָ׻ַ׷鸐濼'JOFHSBJOFE/PUJDBUJPO ؕأ؛٦س⵴ꤐ ⥂㶷דֹ׷ر٦ة㘗ך䭁䓸 63- 㔿㹀㼭侧 FUD ؔ٦ز؎ًؙٝٔٝز ➙䖓؟ه٦زׁ׸׷堣腉

  74. ػؿؓ٦وٝأ嫰鯰

  75. 傈劤Ⰻ㕂ך⡝䨽♰⟝׾嗚稊ׅ׷،فٔ

  76. $PSF%BUB J1IPOFD ˖ Ⰻ⟝《䖤 ˖ ا٦زז׃T ˖ ا٦ز֮׶T ˖ $0/5"*/4嗚稊

    ˖ ا٦زז׃T ˖ ا٦ز֮׶T ˖ ًٌٔ⢪欽ꆀ ˖ .#
  77. 3FBMN J1IPOFD ˖ Ⰻ⟝《䖤 ˖ ا٦زז׃T ˖ ا٦ز֮׶T ˖ $0/5"*/4嗚稊

    ˖ ا٦زז׃T ˖ ا٦ز֮׶T ˖ ًٌٔ⢪欽ꆀ ˖ .#
  78. 3FBMN $PSF%BUB

  79. let request = NSFetchRequest.fetchRequestWithEntityName("Address") let addresses = context .executeFetchRequest(request, error:

    &error) ֿך儗挿ד♰⟝ך ؔـآؙؑزָ欰䧭ׁ׸׷ CoreData
  80. Realm let addresses = realm.objects(Address) ֿך儗挿דכؔـآؙؑزכ ♧ⴖ欰䧭ׁ׸זְ 嗚稊穠卓ך剑⡚ꣲ䗳銲ז䞔㜠ך׫⥂䭯 ˖ ⟝侧

    ˖ 嗚稊勴⟝ ˖ ؙٓأ "EESFTT
  81. Realm let cell = tableView .dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell let address

    = addresses[indexPath.row] postalCode.insertString("-", atIndex: 3) cell.textLabel.text = address.postalcode cell.detailTextLabel.text = address.prefecture ⦼ח،ؙإأ׃׋הֹח ⴱ׭ג㹋ꥷךر٦ة׾《䖤ׅ׷ ֿך儗挿ד׮ת׌ ر٦ةכ《䖤׃זְ
  82. 3FBMNחאְג锃ץ׷ ⿫罋项俱

  83. ˖ Ⱅ䒭8FC؟؎ز"  IUUQTSFBMNJPKQ ˖ (JU)VC  IUUQTHJUIVCDPNSFBMNSFBMNDPDPB  IUUQTHJUIVCDPNSFBMNSFBMNKBWB

    ˖ ِ٦ؠ٦ؚٕ٦ف"  IUUQTXXXGBDFCPPLDPNHSPVQTSFBMNKQ ˖ ؟ه٦زثٍحز"  IUUQTMBDLSFBMNJP ˖ 5XJUUFS"  IUUQTUXJUUFSDPNSFBMN+BQBO ˖ ى٦ز،حف"  IUUQSFBMNDPOOQBTTDPN ⿫罋项俱
  84. 3FBMN+BQBONFFUVQ" SFBMNDPOOQBTTDPN

  85. 3FBMN+BQBONFFUVQ" SFBMNJPKQOFXT

  86. 3FBMN+BQBO6TFS(SPVQ" GBDFCPPLDPNHSPVQTSFBMNKQ

  87. 1VCMJD3FBMN4MBDL" TMBDLSFBMNJP