Pro Yearly is on sale from $80 to $50! »

Modern Core Data(iOS 10)

8e2e0edcf1ffc34e5fbc9ccf7c9a1328?s=47 Noritaka Kamiya
September 28, 2016

Modern Core Data(iOS 10)

8e2e0edcf1ffc34e5fbc9ccf7c9a1328?s=128

Noritaka Kamiya

September 28, 2016
Tweet

Transcript

  1. import CoreData ࠷ۙɺCore DataͲ͏Ͱ͔͢? @nolili Noritaka Kamiya

  2. None
  3. None
  4. None
  5. None
  6. CoreData

  7. CoreData

  8. NSAsynchronousFetchRequest NSFetchRequest<ResultType> NSPersistentContainer

  9. NSFetchRequest<ResultType>

  10. let request = NSFetchRequest(entityName: "Message") context.fetch(request) as! [Message] Force Casting!

    Before
  11. let request: NSFetchRequest<Message> = Message.fetchRequest() // fetchRequest() -> NSFetchRequest<T> ͸ࣗಈੜ੒͞ΕΔ

    let messages = context.fetch(request) // [Message] After
  12. NSFetchRequest<ResultType> NSManagedObjectͷαϒΫϥεΛfetch͢Δ৔߹ʹศར SwiftϑϨϯυϦʔʹ Swift/Objective-C

  13. NSAsynchronousFetchRequest

  14. let request: NSFetchRequest<Message> = Message.fetchRequest() let asyncRequest = NSAsynchronousFetchRequest<Message>(fetchRequest: request)

    { result in let messages = messages = result.finalResult ?? [] } try! managedObjectContext.execute(asyncRequest)
  15. let result: NSAsynchronousFetchResult = try! managedObjectContext.execute(asyncRequest) result.cancel()

  16. NSAsynchronousFetchRequest closureΛ࢖ͬͨඇಉظϑΣονָ͕ʹॻ͚Δ Ωϟϯηϧ͕Ͱ͖Δ ϑΣονͷProgress΋औಘͰ͖Δ iOS 8~

  17. NSPersistentContainer

  18. Α͋͘ΔCore DataͷηοτΞοϓ

  19. /41FSTJTUFOU4UPSF

  20. /4.BOBHFE0CKFDU.PEFM /41FSTJTUFOU4UPSF

  21. /41FSTJTUFOU4UPSF$PPSEJOBUPS /4.BOBHFE0CKFDU.PEFM /41FSTJTUFOU4UPSF

  22. /41FSTJTUFOU4UPSF$PPSEJOBUPS /4.BOBHFE0CKFDU.PEFM /4.BOBHFE0CKFDU$POUFYU /41FSTJTUFOU4UPSF

  23. /41FSTJTUFOU4UPSF$PPSEJOBUPS /4.BOBHFE0CKFDU.PEFM /4.BOBHFE0CKFDU$POUFYU /4.BOBHFE0CKFDU$POUFYU 1SJWBUF2VFVF /41FSTJTUFOU4UPSF

  24. ͭΒ͍

  25. ॳݟࡴ͠

  26. NSPersistentContainer

  27. /41FSTJTUFOU$POUBJOFS NSPersistentContainer(name: "iOS10Sampler")

  28. /41FSTJTUFOU4UPSF$PPSEJOBUPS /4.BOBHFE0CKFDU.PEFM /4.BOBHFE0CKFDU$POUFYU /4.BOBHFE0CKFDU$POUFYU 1SJWBUF2VFVF /41FSTJTUFOU4UPSF NSPersistentContainer(name: "iOS10Sampler") /41FSTJTUFOU$POUBJOFS

  29. It just works

  30. NSPersistentContainer (iOS 10~) Α͋͘ΔCoreDataͷηοτΞοϓΛ؆ུԽ طʹ࢖͍ͬͯΔਓʹ͸౰ͨΓલ͔΋͠Εͳ͍͚Ͳͱ͖ͬͭʹ͘͞͸؇࿨͞Ε͍ͯΔ ۜͷ஄ؙͰ͸ͳ͍ɻCoreDataΛ࢖͍͜ͳͨ͢Ίʹ֮͑ͳ͚Ε͹͍͚ͳ͍͜ͱ͸ଟ͍ɻ NSPersistentStoreDescription Λ࢖͑͹ࡉ͔ͳઃఆมߋ΋Մ

  31. None
  32. None
  33. References iOS 10 Sampler https://github.com/shu223/iOS-10-Sampler What’s new in Core Data

    https://developer.apple.com/videos/play/wwdc2016/242/ SwiftʴCore DataʹΑΔiOSΞϓϦϓϩάϥϛϯά (੢ํՆࢠɺ ؙࢁ߂ࢻ) https://book.mynavi.jp/ec/products/detail/id=50729
  34. https://www.wantedly.com/projects/61105

  35. import CoreData ࠷ۙɺCore DataͲ͏Ͱ͔͢? @nolili Noritaka Kamiya