How to move from CoreData to Firebase - ios

So currently, I am making an app in which it allows the user to create expenses and store them. Each expense has properties such as date, name, amount, type of expense, category and etc. Currently, I am storing all of this on CoreData, which I find is easy and manageable, however I really want to move to database storage so that the app doesn't take up an increasing amount of storage in the user's phone.
I have several questions if someone can answer them.
Can firebase databases be used to store characteristics of an object like core data can sort of like a JSON String?
Can firebase save something and retrieve it if you are not connected to the internet?
Which firebase storage should I use. When I go on their website, they have multiple databases such as RealTime, Cloud Storage and etc. which one would be the best one for what I am trying to do.
Thanks for all the help!

Firebase store data as JSON, So you need to export your Core Data Model structure and values into a JSON format, to upload it on Firebase.
Yes, Firebase allows offline save and retrieve data into DB. You need to enable offline Persistence for that.
You have to use RealTime Database or Cloud Firestore to store data in Firebase database. Cloud Storage is used to store files like images, text files or other files.

Related

User-based Private Data on Firebase

I'm working on an iOS app that connects with Firebase. I was wondering, if it's possible to have data that a user uploads only be accessible to him/her. The docs explained how to do this for Firebase storage, but I'm not sure how to create a similar effect for the database. Is it possible to do this, or will all data be public to all users?
Additionally, if it is possible to have the data only be accessible to the specific user, will the data still be visible to me in the database?
Thanks for your help.
What you are looking for is a concept called "security rules" with Firebase. Is it available with Realtime database and Firestore.
You can restrict access as you described and data remains available to you since you will be the administrator of the database.

Local Cache of CloudKit Records

There's a chapter called Maintaining Local Cache of CloudKit Records in CloudKit documentation on Apple's web site. However, everywhere online people say it's close to impossible to store offline data with CloudKit. I'm relatively new iOS developer. Did anybody tried implementing offline data storage (on device) as per Apple's docs?
If you want true, offline-first data for your app, then yes, you need to add a database of some kind.
Every time you update a record, save it to your database and push the updated record to CloudKit. You can also subscribe to CloudKit changes and update your local database as record changes come in.
Core Data and SQLite are common options. I happen to use the Realm database, which I consider to be a bit simpler to use than Core Data or SQLite. I set it up so that my app's UI only interacts with the offline data in the database (so that it's always available). CloudKit and my Realm database work together to keep the data up-to-date, but my UI never tries to rely on the presence of transitory CloudKit records.
I hope that helps.

Core Data Values Accessed by Multiple Users when logged in (iOS Swift)

I have an app where a UITableView is used to represent a friends list. Now, this table is updated by values stored in core data, and I'm downloading friend values to core data via Parse. Instead of accessing Parse to update the tableView directly, I decided to update Core Data and then the tableView because I need the friend information in other parts of the app, and thought it would be more efficient to use Core Data than to have calls to Parse again and again. Everything works fine!
However, my app has a log in system before users can use the app. And when I created another dummy user to test it, I found that the friend values stored in Core Data by my actual account were being used to update the friend list tableView! When actually the tableView should be empty (new user).
I don't know exactly how Core Data works but I figure it uses some segment of the device's memory to store entities. My question is this, is it possible to use Core Data to store private information related to a particular user that can't be accessed by other users that log into the same device? Or should I continue to make calls to Parse whenever I need information?
Hope you guys understood my question, thanks!
iOS is not a multi-user system. Your app stores its files in a sandboxed folder structure and this sandbox is independent of any user logins you have implemented in your app.
When a new user logs in (or, if you prefer, when a user logs out) it is up to you to remove any data you have stored in Core Data that you don't want another user to have access to.
Parse can save data offline by Local Storage or cache the request by Cache Policy
They are much faster than creating your own database (by CoreData).

Saving large amount of data from Firebase

I actually sizeable amount of data that I retrieve the entire data from Firebase when the user log into the app, or to the different view controllers which require the data from Firebase.
However, I find it meaningless to continuously retrieving the same data as the user navigates through the app. Is there a way for me to save all the data to the phone upon first retrieval after log in and just refer to the local data whenever I need it?
I have used NSUserDefaults for small amount of data but I don't think that it is the right option for my situation.
For these data, I would also require to search them by key when necessary.
You can use any Database such as CoreData, Realm or SQLite(many wrappers available on cocoapods).
You can find difference between the three on on this blog link.

One way sync with Core Data

I am about to build an internal-only iOS app for storing simple business data. The data store will consist of a single entity only, with one entry per day. To start with there will be around two years worth of data (~750 entries).
I want to set the app up to do one-way syncing only. i.e. Only one person can enter data, but others can read it. iCloud is out as it only works for a single user account.
Is there a lightweight way to sync this datastore out from the single write user to the other read users? Setting up a full sync system seems overkill for this case.
Instead of iCloud, you could use one of the online backends such as Parse.com or Simperium. They would allow you to share data using a db and also provide for user accounts, authentication etc. If you want to run the server locally you can investigate DataKit.

Resources