views:

392

answers:

3

Okay this is a fairly broad question. This is my first App and I'm not sure the best way to go about this. The app is on the IPHONE.

I have a 'Restaurant' class. The restaurant has many different attributes and opening times. I currently store a restaurant in an instance of nsdata (it complies to NSCoding) LOcal storage is easy and I just use nsdata.

I have just built in an import/export function. I want these two methods to "post" a restaurant to the web and "get" a restaurant from the web. I know I can do this with NSUrlConnection and I have it up and working.

However I want to be cleverer about it. For instance what if I want to take my online list of restaurants that have been submitted and build a web interface that can also interact with the data?

This is what I am thinking so far: Create a 'toString' method that will convert my class into a textual representation. Then store the string on a server. This will replace storing nsdata online. Does this sound appropriate?

However, I want to be able to query the amount of restaurants and have a bit more control over my online 'database'. Is XML the answer? I was about the start looking into Amazon Web Services and learn either Json or Rest.

Any bits of advice?

Thanks

Dan

+1  A: 

I am not very familiar with iPhone development yet, but if there are reasonably easy way to consume web services I would recommend using that with typed parameters. This would make these services more "usable" from other systems too, they would not need to know how to serialize/pack objects to a string but only how to call a function: storeRestaurang(string name, int rating...) etc.

This is an article I will check out myself since I hope to get into iPhone development a bit more: http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

Fredrik Jansson
+1  A: 

Looks like you want to use a plist. Any of the cocoa collection classes can be written out to a plist, which is a breed of xml file. The sweet part is if you use standard cocoa value classes, you can write the collection out, and read it back in later.

NSString, NSNumber, NSDate, NSData, NSAray, NSDictionary objects can be put into a collection and stored to a plist directly. Other classes will have to be serialized into NSData then written to disk as a plist. For truly custom data, an NSKeyedArchiver is probably what you want.

For simple strings and numbers data, pack it all into an NSDictionary and then write it to a plist. Now look around on your mac and you'll see just how popular plists are.

NSDictionary API - Storing Dictionaries

Property List Programming Guide

Archives and Serializations Programming Guide for Cocoa

Ryan Townshend
Thanks for the response Ryan. Fantastic contribution. I currently use a nskeyedarchiver and nsdata to store my restaurant. I would have used a plist but I currently have custom classes such as 'Restaurant' and 'TimeEntry' the instance variables of these classes are only standard classes.
Dan Morgan
A: 

Learn about REST, it's the easiest and cleanest way to provide a web-based API. Some frameworks, like Ruby on Rails, give you a REST interface right out of the box.

Then, you'll need to find a way to convert your objects on the iPhone into a REST-friendly format. XML and JSON are both options, but unfortunately I haven't seen any code for converting to/from XML or JSON that I can really recommend, since I haven't tried any just yet. But, there are some projects that might lead you in the right direction. One of the most promising-looking is this:

http://github.com/yfactorial/objectiveresource/tree/master