Closed Evertt closed 4 years ago
Hmm, after giving it some thought, I'm afraid that this is maybe not possible? Since Firestore can always only work asynchronously. That's a real bummer.
Thanks for writing in!
I think your hunch is right. Transparent lazy loading is going to block the calling thread which isn't something we want to do. It would be too easy to accidentally block the main thread with this kind of interface. If Swift were to support async/await or promises this is something that could start to make sense. As it stands, this isn't something we can pursue.
Feature proposal
Let's say I have a collection
users
and a collectionposts
. And everypost
looks like this:So the
user
field is a document reference to a user document. It would be nice if my struct in Swift could look something like this:The new
@Reference
property wrapper is what I mean. So let's say you load the data from Firestore using the Swift Firestore encoder/decoder like so:Then the idea is that Firestore's encoder doesn't eagerly load all the related
User
models, but instead it just initializes the property wrapper@Reference
with the string value of the user-reference. And then the property wrapper would function a little likelazy var
in that it only loads theUser
document once some code tries to access it.Is it clear what I mean?
edit
It'd be even better if there could be both a normal
@Reference
propertywrapper and a@LiveReference
one, which is one that subscribes to live snapshots instead of just fetching a single one.