Thanks Ziqiao, for these great ideas!
I've tried both, separately, in my test project....
Replacing the data property with a relationship does indeed avoid loading the images until needed. A good workaround. I'll test it in my real project to see what happens with more complexity and scale.
Using fetchCount on a FetchDesciptor instead of count on SwiftData's Query array also improves things. It does not load the entire dataset to make the count.
So thanks for these workarounds. Used together they may allow a SwiftData app to run normally on iOS 18.
Now just thinking out loud, for myself and for fellow developers facing the same issues, strategizing about iOS 18 (and other fall 2024 os's)....
Changing the image properties to relationships has these costs and risks....
I'll probably have to write a migrator, as this change seems unlikely to be handled automatically by lightweight migration.
Will swift data reliably manage and discard the related items? Any different behavior from being properties?
Changing the queries to FetchDesciptor has these costs and risks....
In my large app, I use the convenience of counting SwiftData's pseudo arrays all over the place. Not just in Queries, but in relationships. How much work will it be to inject FetchDesciptors everywhere? Any performance difference?
Any unforeseen interactions or failures with SwiftUI views?
And the big question, do I just wait a few more Betas and hope that SwiftData's iOS-17-like behavior is restored? Is the old-way I was working closer to SwiftData best practices? When do I give up and make these changes?