supabase / supabase-swift

A Swift client for Supabase
https://supabase.com/docs/reference/swift
MIT License
685 stars 101 forks source link

SwiftData Best Practices #334

Closed paul-brenner closed 5 months ago

paul-brenner commented 5 months ago

I'm moving my app to using SwiftData to store the data a user needs on device so that the user spends less time waiting for Supabase queries to return. I'm not an expert, but I suspect it may be more inline with the way Apple wants developers to use SwiftUI and if I've learned anything it is that the more you align with what Apple is trying to get you to do the less pain.

I saw this discussion, but it didn't go very far.

So, assuming it is a good idea (you can stop me right here if not), I would think that this repo could benefit from having an example of how to do that that the community can use for inspiration or improve on. That said, I'm also assuming the maintainers are plenty busy with everything else that is not this. If it actually has a reasonable likelihood of being useful I could try to put together a stripped down version of what I'm doing as a sample app.

The plus side would be that it is at least something for people to consider and work from. The negative would be that I may be doing horrible things that would waste maintainer time to even review and shake their heads at.

If I don't hear back I'll just assume this offer would do more harm than good, but if you think it might help I'll work on contributing and example.

im-murilo commented 5 months ago

I think it'd be great to have more examples and documentation on how to integrate with SwiftData, I tried it a bit but it was painful so I gave up.

grdsdev commented 5 months ago

Hi all,

Supabase works with Codable types, and it makes no assumption on any local storage, one approach would be to make your @Model classes conform to Codable (https://www.donnywals.com/making-your-swiftdata-models-codable/), and use it directly as Supabase response/request objects.

Other than that, there's no best practices to make Supabase work with SwiftData, as they are unrelated frameworks, how data is structured it will depend on the application structure.

For now, it is up to the developer to implement a persistence layer that coordinates the data between Supabase <-> Local Storage.

@im-murilo I'd be glad helping you with the issues you had setting up SwiftData for storing the Supabase's objects if I'm able to.

Thanks.

paul-brenner commented 5 months ago

Fair enough! I'll close this. Thanks for all the hard work