Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-evaluate Data persistence Layer #12

Closed
shayneptorres opened this issue Mar 8, 2020 · 7 comments
Closed

Re-evaluate Data persistence Layer #12

shayneptorres opened this issue Mar 8, 2020 · 7 comments

Comments

@shayneptorres
Copy link
Contributor

Right now, it looks like the personal contact info is being stored separately as a name and a number in UserDefaults. While this works I believe that there is a better way to persist this information which will make querying it much easier, manageable, and safe.

Some suggestions are:
1.) Model the personal contact info in a Codable class that can be serialized/deserialized into UserDefaults, that way we don't have to check the individual keys (ie "name1", "number1"). This will also allow the user to store an arbitrary number of personal contacts, instead of the hard limit that we are setting
2.) Model the personal contact info in CoreData. If we don't want to rely on UserDefaults we can turn to CoreData to model and manage the persistence of our personal contact info
3.) Model the personal contact info with Realm. This is another Database tool that I use in all of my projects. It is much easier to setup and user (in my opinion) than CoreData. Setting it up in Realm will help if there are things in the future that we want to persist.

There are pros and cons to each, but let me know what you think.

@eddielement
Copy link
Contributor

Agreed! I feel like this could apply for all elements of the safety plan (which are all in UserDefaults), not just personal contacts. Could you dive into the pros and cons of each? Out of the 3 options you listed, I've only ever worked with Realm before.

@shayneptorres
Copy link
Contributor Author

User Defaults
Pros:

  • Lightweight: Does not require much setup or overhead that comes from importing a database layer

Cons:

  • No way to clearly/strictly model data, we have to manage it through keys
  • Not great at querying/filtering data.
  • Modeled data is not what User Defaults was made for

Core Data
Pros:

  • Supported by Apple: Since core data is supported by Apple, the updates are taken care of whenever there is an update. No waiting for 3rd party developers
  • Is the default implementation for many different apps
  • Versioning/migrations is simple
  • We can assume core data will be around for as long as iOS development is around

Cons:

  • If not imported into the app from the start, it can be bit tricky to setup the persistence containers

Realm
Pro:

  • Very easy to setup
  • Versioning/migrations are simple
  • Realm works for Android too, so both platforms can use the same database layer
  • Very easy to model relationships

Cons:

  • It is not thread-safe so extra precautions must take place if we want to implement asynchronous features with Realm
  • It is a big library, the biggest of the three options.

As a disclaimer, I have only used Core Data for a number of projects so I am not incredibly familiar with everything it has to offer. I use Realm in all of my personal projects and and my work projects. My vote would go towards using Realm but I am willing to be persuaded.

@eddielement
Copy link
Contributor

I wonder if @prolefeed has any thoughts here? (Since he's planning to work on rewriting the Android app into Kotlin.)

@shayneptorres
Copy link
Contributor Author

@eddielement As we are finishing up the Swift conversions, I believe that this issue would be an important one to implement. Did you have any further thoughts? I would throw my vote in for using Realm but wanted to get your thoughts

@eddielement
Copy link
Contributor

I would vote for Realm too! Let's do it! @shayneptorres

@shayneptorres shayneptorres changed the title Re-evaluate Personal Contact Persistence Re-evaluate Data persistence Layer Mar 18, 2020
@shayneptorres
Copy link
Contributor Author

shayneptorres commented Mar 18, 2020

Sounds good, I will begin working on the implementation of Realm for the data persistence layer. I will create a new Issue specifically for the Realm implementation.

@shayneptorres
Copy link
Contributor Author

Work for this issue will be tracked in Issue-19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants