rrnarayan1 / omni-crosswords

An iOS app that fetches crosswords and allows users to complete them
GNU General Public License v3.0
26 stars 2 forks source link

A question about Core Data and Firebase #11

Closed AmyAmeliaLee closed 10 months ago

AmyAmeliaLee commented 1 year ago

Hi, this is not an issue, instead, I have a question about Omni crosswords data storage.

Reading the code, I've noticed you use Core Data with Firebase, which is quite unusual. Not Core Data with CloudKit (and Omni crosswords seem to have CloudKit enabled in project settings). Also, Firebase Firestore has a default offline caching system, but you use Core Data instead.

Why such an unusual combination of Core Data for offline and Firebase Firestore for online? Do you plan to move to CloudKit or go full-on Firebase? Do you need any help with that?

rrnarayan1 commented 1 year ago

I'll take your question in a couple parts:

Not Core Data with CloudKit

The database of puzzles runs on my own server, and my server uploads the crossword metadata to a free firebase store. There is only one database/table that stores all crossword metadata.

and Omni crosswords seem to have CloudKit enabled in project settings

This is true, but I only CloudKit for GameCenter syncing, which uploads the user's completed/in-progress puzzle to CloudKit (so it should only be accessible by that user). https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/GameKit_Guide/SavedGames/SavedGames.html

In general, the user's actual data is never actually accessible by me and is stored completely locally, which is why I chose to use CoreData.

Also, Firebase Firestore has a default offline caching system, but you use Core Data instead.

Like mentioned above, I think this is better suited to a system where the user's data is stored/written to Firebase. That's not actually the case for this app. According to the Firebase docs, re offline caching: "When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the Cloud Firestore backend." the user's game data is never stored in Firebase today.

tl;dr: user data isn't stored in Firebase, it's only stored on device (or in CloudKit for GameCenter syncing). What's stored in Firebase is generic crossword metadata.

AmyAmeliaLee commented 1 year ago

Now I understand your concept better, thank you!

One could argue that you may ditch Firebase altogether, and seed crosswords directly from your server (if you know backend programming). Or opt-in for CloudKit storage and upload crosswords from your server to CloudKit via CloudKit Web services. That way you will have a native syncing process between CloudKit-CoreData.

But if it works - it works, and that's great.

rrnarayan1 commented 1 year ago

One could argue that you may ditch Firebase altogether, and seed crosswords directly from your server

Yes, I was thinking about this, but Firebase is much more scalable and I don't have to worry about my own server's uptime.

Or opt-in for CloudKit storage and upload crosswords from your server to CloudKit via CloudKit Web services. That way you will have a native syncing process between CloudKit-CoreData.

Also possible - though I would prefer using Firebase for any future cross-platform initatives / authenticated requests.