suicidesafetyplan / safetyplan-ios

Suicide Safety Plan is a free mobile application for suicide prevention.
MIT License
23 stars 10 forks source link

Re-evaluate Data persistence Layer #12

Closed shayneptorres closed 4 years ago

shayneptorres commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

User Defaults Pros:

Cons:

Core Data Pros:

Cons:

Realm Pro:

Cons:

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 commented 4 years ago

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

shayneptorres commented 4 years ago

@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 commented 4 years ago

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

shayneptorres commented 4 years ago

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 commented 4 years ago

Work for this issue will be tracked in Issue-19