Рет қаралды 7,564
Core Data and SwiftData are both frameworks that help you store the user's data in a SwiftUI application. In this video, I share my experience of converting a complex Core Data project to SwiftData. I discuss the advantages, missing features, and issues I encountered during the process.
I aim to provide a comprehensive comparison between Core Data and SwiftData, showcasing the similarities and differences between the two frameworks. By the end of the video, you will have a good understanding of what it’s like to work with SwiftData and be able to make an informed decision about whether to migrate an existing Core Data project or start a new app with SwiftData.
I begin by explaining what SwiftData is and clarifying that it is not built on top of Core Data but is a separate framework specifically designed for Swift and SwiftUI applications. I highlight the advantages of using SwiftData, such as working with native Swift types and SwiftUI, as well as the ease of transferring learnings from Core Data to SwiftData.
Throughout the video, I compare the tools and concepts used in Core Data and SwiftData, such as persistent containers, managed object models, predicates, and macros. I discuss the convenience of writing filters in Swift code instead of using strings and the promise of type safety.
I delve into the challenges and limitations I encountered while working with SwiftData. I touch on issues with relationships, enums, optionals, and sorting. I explain how queries and fetching data can be problematic, particularly in terms of dynamically changing predicates and sorting. SwiftData does not offer section queries and does not support UIKit with an equivalent of NSFetchedResultsController.
I touch on the difficulties of implementing MVVM architecture with SwiftData and the limitations of querying and previewing data.
I acknowledge the positive aspects of SwiftData, such as its integration with the new observation framework, which enables more efficient data flow. I talk about the support for Swift concurrency and the convenience of auto-saving data in SwiftData.
In conclusion, I express my personal opinion that SwiftData is not yet ready for production use. I believe there are still too many bugs, missing features, and limitations that need to be addressed. I recommend sticking with Core Data, a proven framework with extensive documentation and resources, unless there is a significant improvement in SwiftData.
I am using macOS Ventura 13.4 and Xcode 15 beta 5
⬇️ Github project github.com/gah...
overview
00:00 Introduction
01:00 What is SwiftData and how is it different to CoreData
04:33 Model definition in SwiftData and limitations
07:30 @Query and dynamic updates
14:52 Predicate marco problems for advanced filtering
16:25 SwiftData with Observation feature for improved data flow and performance
19:04 SwiftData and Xcode previews ??!
22:50 Auto save
23:26 More missing features and problems
25:41 Wrap up and my personal recommendation of SwiftData vs CoreData
If you liked what you learned and you want to see more, check out one of my courses!
👨💻 my SwiftUI course school.swiftyp...
👨💻 my Core Data and SwiftUI course school.swiftyp...
#swiftdata #coredata #swiftui