Reputation: 1729
I am building an app that will require an offline mode when unable to get a wifi or data connection.
I am wondering what is the best solution for the following scenario.
Lets say my app allows users to view, add , amend an event on a calendar.
For the app to work off line i only need to store the current days worth of events. This could be be between 1 - 10 events. Each event will have a name, description and various other small properties.
I have been looking at coreData and am wondering if this maybe a bit overkill for what i need. I don't need to mirror the whole DB or anything like that.
Can I constructively use NSUserDefaults to store this king of information. What are NSUserDefaults limitations in terms of what types you can store and how much.
The off line version will possibly need to store more entities than just the above so is it a viable method of storing data providing the amount of data is't massive.
Any advice would be great.
Upvotes: 1
Views: 2002
Reputation: 40030
NSUserDefaults
is really meant for storing small pieces of data such as settings, preferences, and individual values.NSUserDefaults
offers a trivial learning curve and thread safe implementation.CoreData
and related classes provide easy ways to get your entities into UITableViews, like NSFetchedResultsController
.CoreData
abstracts away a lot of the messy things you'd otherwise have to deal with yourself, such as lists of objects, one-to-many or many-to-many relationships, or constraints on object attributes, into a single nice clean object-oriented interfaceCoreData
manages save and undo functionality for you. It has a persistent store, which tracks changes, and can be flushed to the disk automatically at any number of timesHowever, if you're new to Cocoa I would avoid CoreData
, to give yourself a chance to learn the basics first.
If I had to choose I would dive directly into CoreData
. It makes sense also for small projects. NSUserDefaults
is not meant to be used as a database (all the operations are ran on the main thread).
Upvotes: 1
Reputation: 2121
Coredata may be an overkill at first, but as your app grows so does your datamodel. CoreData is designed for such changes.
NSUserDefaults will store anything as long as the object complies to the NSCoding protocol, but its not meant to store a lot of information. Besides that, it can be difficult to fetch the data in NSUserDefaults, while it is rather easy in CoreData. Also note that relations between objects are unmanageable when storing objects in NSUserDefaults.
Upvotes: 0