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

My SwiftData Review

My SwiftData Review

My SwiftData Review
SwiftDataの評価に関する私見

Avatar for Kishikawa Katsumi

Kishikawa Katsumi

July 14, 2023
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. What Is SwiftData? SwiftDataͱ͸ʁ • Introduced at WWDC 2023 •

    Data persistence framework • Works great with SwiftUI
  2. What Is SwiftData? SwiftDataͱ͸ʁ • Introduced at WWDC 2023 •

    Data persistence framework • Works great with SwiftUI • Core Data wrapper 🔑
  3. What Is SwiftData? SwiftDataͱ͸ʁ • Introduced at WWDC 2023 •

    Data persistence framework • Works great with SwiftUI • Core Data wrapper 🔑
  4. SwiftData Is Just Wrapper of Core Data SwiftData͸Core DataͷϥούʔϥΠϒϥϦͰ͋Δ •

    Not reworked Core Data • Provides a more user-friendly API for working with Core Data in Swift • Schemas de fi ned in code • No separate mapping fi le (*.xcdatamodeld) • Type safe queries • Eliminate string-based Key Paths
  5. SwiftData Simplifies the Core Data API Core DataͷAPI͕ΑΓγϯϓϦʹ࢖͍΍͘͢ • NSPersistentContainer

    => ModelContainer • NSManagedObjectModel => PersistentModel • NSManagedObjectContext => ModelContext • NSPredicate => #Predicate • NSPersistentStoreCoordinator => 🗑 • *.xcdatamodeld => 🗑
  6. The issue is Core Data ݁ہͷͱ͜Ζɺ૪఺͸Core Data • For those

    familiar with Core Data, • Core Data is proven, stable, simple and convenient. • For those unfamiliar with Core Data, • Core Data is di ffi cult to control and is a black box
 that causes mysterious errors and crashes.
  7. Why argue for and against Core Data? ͳͥCore DataͷධՁ͕෼͔ΕΔͷ͔ •

    CoreData is not relational database • However, many expect Core Data to be SQLite ORM
  8. Core Data Is Not Relational Database (Nor ORM) Core Data͸Relational

    DatabaseͰ͸ͳ͍ʢORMͰ΋ͳ͍ʣ • CoreData Is Object Graph Manager
  9. Misconception that CoreData is not RDB CoreData͸RDBͰ͸ͳ͍ͱ͍͏͜ͱ΁ͷޡղ • Apple just

    says it for marketing purposes • Support for data stores other than SQLite (Binary, XML, In-Memory) • SwiftData supports SQLite only. Therefore, it is a wrapper for SQLite.
  10. Misconception that CoreData is not RDB CoreData͸RDBͰ͸ͳ͍ͱ͍͏͜ͱ΁ͷޡղ • Apple just

    says it for marketing purposes • Support for data stores other than SQLite (Binary, XML, In-Memory) • SwiftData supports SQLite only. Therefore, it is a wrapper for SQLite.
  11. Misconception that CoreData is not RDB CoreData͸RDBͰ͸ͳ͍ͱ͍͏͜ͱ΁ͷޡղ • Apple just

    says it for marketing purposes • Support for data stores other than SQLite (Binary, XML, In-Memory) • SwiftData supports SQLite only. Therefore, it is a wrapper for SQLite. • Completely di ff erent, technically • CoreData is object graph manager • Object graph is groups of objects form a network through their relationships with each other.
 In short, it is a collection of objects.
  12. CoreData Is Not Relational Database CoreData Is Object Graph Manager

    • Many to Many relationships • No foreign key required
  13. Available Data Types อଘͰ͖ΔϓϩύςΟͷܕ • Primitive Types • Int, Float,

    Double, String, Bool • ❌ CGFloat • URL, UUID • Codable • ❌ Enums
  14. Auto Save Is Enabled, No Way to Detect Errors Auto

    Save͕༗ޮͳͱ͖ɺอଘࣦഊΛ஌Δ͢΂͕ͳ͍ • Seems to work correctly, but data is lost on exit • Migration failures silently erase existing data
  15. #Predicate Macro Has Many Unsupported Features #PredicateϚΫϩ͸ະαϙʔτͷػೳ͕ଟ͍ • Case Insensitive

    Search • Su ffi x Search • Date formatting and Compare • Max/Min • Composite Unique Constraint
  16. Is SwiftData Production Ready? SwiftData͸࣮༻Մೳ͔ʁ • Depends on how familiar

    you are with Core Data. • No Fine-Grained CoreData Controls • No Faulting • No Parent/Child Context • No Merge Policy • SwiftData Itself Is Also Incomplete
  17. Conclusion ݁࿦ • SwiftDataͷ࠾༻͸৻ॏΛཁ͢Δ • Core Dataͷܦݧ͕ඞཁ • ORMΛٻΊ͍ͯΔͳΒORMΛ୳ͦ͏ •

    ແ੍ݶʹϢʔβʔ͕σʔλΛ࡞੒͢ΔΑ͏ͳ༻్ʹ͸޲͔ͳ͍ • ͍ͭͰ΋σʔλΛফͤΔΩϟογϡͳͲͰࢼͦ͏