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

My journey taming Core Data: An intro to the CoreStore library

My journey taming Core Data: An intro to the CoreStore library

Presented at the October 2017 Tokyo iOS Meetup.

John Estropia

October 14, 2017
Tweet

More Decks by John Estropia

Other Decks in Technology

Transcript

  1. MY JOURNEY TAMING CORE DATA AN INTRO TO THE CORESTORE

    LIBRARY TOKYO IOS MEETUP JOHN ESTROPIA
  2. WHAT I'LL TALK ABOUT TODAY ▸ How I approached everyone's

    hate of Core Data ▸ Some CoreStore tricks to do common object persistence tasks
  3. THE REASON? ▸ Speed? ▸ It's fast ▸ Database integrity?

    ▸ battle-tested for years ▸ Memory footprint? ▸ good lazying and caching mechanism ("faulting")
  4. OTHERS: WROTE CORE DATA WRAPPERS ▸ Their approach: ▸ hide

    as much complexity as possible ▸ Syntax sugars ▸ Problems: ▸ Too much magic ▸ API users become too spoiled (pitfalls)
  5. REALM: BUILT THEIR OWN SOLUTION ▸ Realm's primary marketing: ▸

    "an alternative to SQLite and Core Data" ▸ Good API, fast database ▸ Issues: ▸ Some areas still need catching up (e.g. Migrations/ Versioning) ▸ Realm developers have proven they can catch up
  6. ME: ALSO WROTE A CORE DATA WRAPPER ▸ CoreStore's approach:

    ▸ Make things easier, but just enough to keep users aware of pitfalls ▸ "Bad practices" should not be allowed to be written in the first place
  7. BUT WHY NOT JUST USE REALM? ▸ I started writing

    CoreStore in 2015 (Swift 1 beta) ▸ about 1 year before Realm was released
  8. BUT WHY NOT JUST USE REALM? ▸ This is not

    a "Which is better?" debate ▸ If speed is a must, go with Realm ▸ I like Core Data's completeness as an Object Graph Manager ▸ Options are good for us!
  9. CORE DATA ISSUE 1: CROSS-THREAD CONSISTENCY ▸ CoreStore enforces transaction-based

    updates ▸ Main thread objects are read-only ▸ No way to save edits except inside transactions ▸ 3 kinds of Transactions ▸ Asynchronous ▸ Synchronous ▸ Unsafe
  10. CORE DATA ISSUE 3: TEDIOUS MODELS ▸ Xcode model editor

    and NSManagedObject ▸ Need to sync *.xcdatamodeld (XML) files and NSManagedObject subclass source files ▸ CoreStore has a pure-swift way to create models
  11. CORE DATA ISSUE 4: MODEL VERSIONING HAS INCREASING COST ▸

    CoreStore offers Progressive Migrations ▸ Just worry about the latest migration every time
  12. OTHER CORESTORE FEATURES ▸ Type-safe observers for objects and lists

    ▸ Efficient importing utilities ▸ custom sources (e.g. JSON) ▸ uniquing ▸ Support for 3rd-party logging frameworks
  13. SUPPORT ▸ Huge README documentation ▸ Full source code documentation

    ▸ Slack group: http://swift-corestore-slack.herokuapp.com/ ▸ Demo App