SwiftData vs Core Data
SwiftData vs Core Data 관련
Updated for Xcode 15
Although SwiftData builds on top of Core Data, not all the functionality has been exposed for us to use. This means quite a few major Core Data features are not yet supported for developers working exclusively in SwiftData, including:
- We don’t have an equivalent of
NSCompoundPredicate
, for creating complex, multi-step predicates. - We don’t have an equivalent of
NSFetchedResultsController
, for executing then monitoring queries for changes. - There is no support for derived attributes, so things like an automatic
lastUpdated
property aren’t possible. - There are no sectioned fetched requests.
- SwiftData does not support abstract classes or child contexts.
- Or pinning to a specific query generation.
Everyone will have different priorities for those features, but for me missing the first two is hard. Hopefully we’ll see SwiftData continue to improve rapidly over time, until we eventually reach full parity with Core Data.
You should also keep in mind that SwiftData is extremely new, whereas Core Data has been in constant development for about 20 years. This means you’re likely to hit edge cases and surprises on a fairly frequent basis, and I think it’s fair to say that SwiftData has more sharp edges than a porcupine’s dance party. Do things exactly right and you’ll be happy, but a lot of the time you’ll find yourself staring at a crash wondering which small but apparently critical mistake you made.
Don’t despair – it will get better! In the meantime, please watch out for the many things marked Important or Tip in this guide; I’ve gone through the pain for you, so please save yourself the hassle and learn from that pain rather than repeating it.