I’ve been following the CWC+ courses about the chat app and firestore.
I’m now building my own application that makes use of the new Swift Data available from iOS 17, but I can’t figure out how to solve a problem.
When I create a new Swift Data @Model, I cannot use property wrappers, meaning that I can’t use @DocumentId and @ServerTimestamp.
I’d like to use Firestore and Swift Data in conjunction because I don’t want the user to download a possibly large quantity of data every time they open the app, but rather store the bigger part of it locally, and fetch only updates.
I though of defining two separate models, one with firestore’s wrappers, and the other without them; fetch firestore as a firestore model, and then parse it into the SwiftData model, but this is not that elegant and would require quite a lot of duplicated code, as it would mean having two, almost equal models, for each model that I need.
Does anyone have any suggestion on how could I handle this?
Since you’re thinking about caching a big chunk of the data locally, I assume most of it doesn’t change. Which means you shouldn’t have to download thousands of documents on every app init, maybe you should aggregate some of it in just a few docs. Maybe cache it locally and fetch only what’s new. You could maybe save thousands of document reads for each user, which adds up pretty quickly.
You’ll still have to pay for bandwidth, and like Mikaela says you gotta figure out how much data overall this represents. You can get a rough estimation by figuring out number of characters and using a tool like this Convert Character to Byte