After building out a sample project, it appears some derived data stuff hit me. Building the sample app proved that all the approaches above (including what I was doing initially) work. I cleared all my Xcode cache and tried it in my project and it seemed to work. Part of my issue as to why I wasn't seeing the data either might have been that this query
@Query(
filter: #Predicate { recipe in
recipe.book?.title == "Sample Book #1"
},
sort: \.name
)
private var recipes: [Recipe]
doesn't work. I'm not exactly sure why this is, maybe it's just me not fully understanding how #Predicate functions, but looking at it, this should work.
The query example that @malc posted doesn't appear to work either. I have prints in place to depict this. There are 3 different versions. 2 of them return an empty array, while 1 of them doesn't even compile. Now that i'm onto Queries, this is probably out of scope of this thread, but wanted to bring it up anyways in case anyone has any ideas there.
I've attached a sample project that explains the different approaches I have used for generating Sample data, as well as how I got around the @MainActor but with the #Preview macro. I figured this would probably be a good point of reference for anyone that ends up in my shoes.
I wasn't sure of the best way to handle uploading the sample project, so I threw it in my S3 bucket. http://anth.io/SwiftDataDemo.zip
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: