Saving data compared

When building apps for the iPhone using Swift/xCode there needs to be a way to save the users data.
I believe there are two ways to save this data; using Data Persistence, or using Core Data.
What would be the reasons for choosing one over the other?

Core Data is very useful when your information is structured and you want to exploit relationships to explore the data graph. For example a person has a home which has a set of utilities - you can use an expression like "person.home.utilitties where name=“electricity” to find out about their electricity service. Persistence is also a little bit simpler, you do not need to write individual objects to file, you just tell the managed object context to save and all changes to all your current objects are saved. One reason you might NOT use CD is when you need to store binary data, it is not particularly efficient at that - in that case you might store a reference to the data but store the data itself in a filesystem.

Data Persistence covers a few things, such as writing a text file from a string, a plist from a dictionary or even individual keys using NSUserDefaults. I reach for these when the data isn’t structured and the overhead of creating the core data model and the managed object context is just too much.

There’s no definitive answer though… there are times when you think you might one day expand what you store so simple stuff goes in Core Data, there are times when you go for the simplicity of writing plists even when things are more complicated. If you say a little more about what kind of data you might be storing that would help.

1 Like

Thank you for that explanation, it will help me with my decision.
The first version of the app I’m working on will be simple with not that much data to save; mostly names, small images and a rating view.

The next version, each of two lists will have more details. Example: Book List has two variables - title and image, later it will have rating, availability, quantity and which group will review. Reviewer List has two variables - name and age, later this group will also have availability and an algorithm for sorting into groups for the reviews of the books and how many group reviews each has completed. This is a simple example, hope it helps.

So if I compare persistent store to “ms access” and core data to “sql” on how each handles amounts of data, would this be somewhat of a good comparison?

I can’t say exactly because I don’t know the underlying technology behind MS Access - I always thought it was a visual database with relationships, similar to SQL but proprietary.

Anyway, Core Data actually is SQL - you will find .sql files in your simulator if you dig, and you can edit them with a SQL editor. That can be very handy for test and debug. Though you should not think of it in terms of SQL if you can help it :slight_smile: From what you describe I think Core Data is going to be a good match for your book/reviewer database, since you will probably want to see all reviews for a book, for example, and having that relationship in Core Data will make that fetch really easy.