What is SwiftData?
What is SwiftData? 관련
Updated for Xcode 15
SwiftData is a fast, powerful, and easy-to-use way to store data in apps built for iOS, macOS, tvOS, watchOS, and even visionOS. It lets us create custom objects, define how they link together, retrieve them with filtering and sorting, and even synchronize them to iCloud – and much more too.
Not only does SwiftData take full advantage of the latest Swift language features, but it’s also built with SwiftUI in mind: if you’re building apps with SwiftUI, you’ll find SwiftData slots in almost invisibly.
Behind the scenes, SwiftData is powered by a much bigger and more mature framework called Core Data. That brings all sorts of benefits, not least 20 years of development and maturity. But SwiftData is more than just a simple overlay: Apple really went to town in isolating and resolving the key pain points developers were reporting with the older framework, meaning that SwiftData is a significant improvement for anyone who has used Core Data in the past.
One downside is that SwiftData supports only iOS 17 or later, along with other coordinated releases – that’s macOS Sonoma, tvOS 17, watchOS 10, and visionOS 1.0.
SwiftData makes a great choice for any kind of on-device storage, including:
- Permanent storage of user data, such as their to do lists or cooking recipes.
- Temporary storage of user data, where SwiftData is used as a cache for data fetched from a server.
- Document-based apps, e.g. text or video editors.
- Complex user settings or history data.
It’s less of a great choice when:
- You need to support many users using iOS 16 and earlier. Although SwiftData and Core Data can live side by side by in the same app, it’s extra work.
- Your data is stored only in CloudKit or another equivalent service, and you need to be using live data at all times.
- You need the full range of capabilities offered by Core Data. Many features from Core Data have yet to surface in SwiftData, so if you have more advanced use-cases you should probably stick with Core Data for now.