This is a demo project that I made to test the new SwiftData framework. I wrote a few blog posts about the topic, where I reference this project. Have a look here:
- Introduction to Data Persistence in SwiftUI with SwiftData
- Modeling Data in SwiftData
- SwiftData Stack: Understanding Schema, Container & Context
- Data Handling in SwiftData: Create, Read, Update, Delete
- How to fetch and filter data in SwiftData with Predicates
- How to convert a CoreData project to SwiftData
It is an app where you can collect code snippets.
I wrote this project with Xcode 14 beta 2. There are still a lot of bugs with SwiftData. You can have a look at the list of reported issues in the latest Xcode release documentation: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes and the iOS 17 beta release notes: https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-17-release-notes
I used 3 model types: Folder, Snippet and Tag. There is a one-to-many relationship between Folder and Snippet and a many-to-many relationship between Snippet and Tag.
The Snippet type is the most interesting one, where I used different property types like Booleans, Integers, custom types, and image data.
I had quite a lot of problems with the previews. In the demo, I used a few different ways to pass SwiftData data to the preview. All previews are working. Note that this is very likely to improve in the upcoming betas.
SwiftData does not allow dynamically changing sorting and filtering for @Query like CoreData with @FetchResult. But you can set these parameters in the initializers. Have a look at the tag list, where I implemented searching and sorting.