Bruno
Bruno

Reputation: 1032

Saving requestes from users

I have the following problem. I need to make an application for a restaurant, the user will be able to pick a dish and add preferences to that same dish like, more salt, fries etc... the App reads all the dishes and preferences online. I`m thinking of using NSUserDefaults to temporarily save the requests before sending them to the server. There are some factors to have in consideration:

  1. The user can edit the request.
  2. The user can delete the request.

What will be the best approach to build this App? NSUserDefaults or CoreData?

Thanks in advance.

Upvotes: 0

Views: 67

Answers (3)

dalton_c
dalton_c

Reputation: 7170

Neither. I'd say implement a custom class that implements the NSCoding protocol. NSCoding requires you to implement two methods:

- (id)initWithCoder:(NSCoder *)aDecoder;
- (void)encodeWithCoder:(NSCoder *)aCoder;

From there, you'll use something like[NSKeyedArchiver archiveRootObject:myCustomDishArray toFile:[self dishesFilePath]];

most Cocoa classes already implement the NSCoding protocol, like NSArray, so if you have an array of instances of your custom class, you can just archive the array. More info about the NSCoding Protocol Here.

Upvotes: 1

Dan Shelly
Dan Shelly

Reputation: 6011

If you are not familiar with CoreData and have relatively small number of data items you might be better off with NSUserDefaults.
However, the correct aproach in my opinion would be using CoreData as it is much more flexible and efficient, and the data you save has contextualy nothing to do with the user defaults (I would use user defaults only to save application wide data and settings, not data records). Updates, insertions and deletions of data records are much more convinient with CoreData.

Upvotes: 1

Idan Moshe
Idan Moshe

Reputation: 1533

Core data is mainly for handling massive data and personally I don't think you need to use it for a restaurant.

Upvotes: 1

Related Questions