Advertisement
Advertisement

More Related Content

Advertisement

Core Data in Modern Times

  1. Core Data in Modern Times Jorge D. Ortiz-Fuentes @jdortiz #CoreDataMT
  2. A Canonical Examples production #CoreDataMT
  3. Agenda ★ Background info ★ Comparisons • Realm • Android Content Providers ★ Concurrency in Core Data ★ Threats to Core Data ★ Protect yourself
  4. Background Info
  5. Core Data concepts ★ Data persistence • Objects <-> Data ★ Relationships • 1-1 • 1-M • M-M ★ Store independence
  6. Core Data Persistent Store Persistent Store Persistent Store Coordinator Managed Object Model Managed Object Context MO MO MO MO MO
  7. Core Data Virtues ★ Visual model ★ Seamless integration with Objective-C ★ Relationships, deletion rules, Faulting & Uniquing ★ Undo management and Change tracking ★ KVC & KVO ★ Filtering, sorting, grouping ★ Versioning and migration ★ Merge policies
  8. FetchedResultsController Anatomy ★ iOS only ★ Controller • uses a fetch request • coordinates getting data and caches them • notifies of changes
  9. Bindings ★ OS X only ★ Sync UI and Coredata ★ Reduce the amount of code required
  10. Comparisons are odious
  11. Realm
  12. Realm: Pros & Cons ★ Born mobile ★ Models in code(PK) ★ Built in encryption ★ Multi-thread & Multi-process ★ Good performance ★ No delete rules ★ No fine grained notifications (KVO) ★ No null properties ★ No sync solutions
  13. Android Content Providers
  14. Android Content ★ Content providers • Abstract data sources • Access to data via URI (REST style) • It can be exported to other apps • Thread safety via synchronized (or multi- instance) ★ Content resolver to map authorities to providers
  15. Concurrency in Core Data
  16. Background Queue Main Queue Single process approach ★ Context • Private • MainQueue ★ Nested contexts • Save pushes changes to parent (no I/O) • Parent saves in the background child MOC pStore parent MOC
  17. Good practices ★ Avoid premature optimization ★ Have a police for when to use concurrency ★ Really follow 1 & 2
  18. Also available now ★ Batch updates (Brent Simmons’ problem) ★ Asynchronous fetching
  19. UIManagedDocument ★ Uses the model in the bundle ★ Async I/O ★ Completion blocks after opening or saving ★ Parent is in background and autosaves ★ Also additional data
  20. Threats to Core Data
  21. Threats ★ Swift • Introspection is still half baked (@NSManaged) • Many features of Cocoa depend on the runtime ★ Lack of multi-process capabilities ★ Apple generated doubts: • Photos using • Removed from Lister?
  22. Protect yourself
  23. – Robert C Martin (Uncle Bob) “The database is a detail!”
  24. Clean Architecture View (VC) Presenter Wireframe Interactor Repository Persistence WSC
  25. canonicalexamples.com coupon: COCOAHEADSNL
  26. Thank you!
  27. @jdortiz #CoreDataMT
Advertisement