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

WWDC Party Intro to CoreStore

WWDC Party Intro to CoreStore

Avatar for John Estropia

John Estropia

June 26, 2020
Tweet

More Decks by John Estropia

Other Decks in Technology

Transcript

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

    LIBRARY WWDC PARTY - OPEN SOURCE GET TOGETHER JOHN ESTROPIA
  2. ▸ @JohnEstropia ▸ Principal Engineer @ (Tokyo) ▸ OSS ABOUT

    ME http://github.com/JohnEstropia/CoreStore
  3. WHAT I'LL TALK ABOUT TODAY ▸ How I approached everyone's

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

    ▸ battle-tested for years ▸ Memory footprint? ▸ good lazying and caching mechanism ("faulting")
  5. 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)
  6. 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
  7. ME: ALSO WROTE A CORE DATA WRAPPER ▸ CoreStore's approach:

    ▸ Make things easier, but just enough to keep users aware of pitfalls
  8. BUT WHY NOT JUST USE REALM? ▸ I started writing

    CoreStore in 2015 (Swift 1 beta) ▸ about 1 year before Realm was released
  9. 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
  10. THIS GUY PROBABLY JUST DOESN'T WANT TO TRY REALM ▸

    Well... ▸ https://realm.io/addons/ https://github.com/eure/RealmIncrementalStore
  11. 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
  12. 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
  13. CORE DATA ISSUE 4: MODEL VERSIONING HAS INCREASING COST ▸

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

    ▸ a backwards compatible port of DiffableSources API that works on iOS 11 and iOS 12 ▸ Efficient importing utilities ▸ custom sources (e.g. JSON) ▸ uniquing ▸ Support for 3rd-party logging frameworks