Connor
Connor

Reputation: 4168

Web-based back-end for simple iOS app?

I made my first (super trivial) iOS application on a plane ride home last night. If any of you have ever read iOS Programming, it's the first one in there. Basically, it's a quiz app - there are two buttons and two labels. The first label is a question, and you tap one of the buttons to show the correct answer, then the other label has the correct answer. The other button is to progress through the array of questions.

Anyways. My question is - I'd like to actually use this while I'm in school. I'd want to set up a rails back-end (or something similar, even if it's run locally) and store the questions and answers there. I can do that no problem, but I have almost no idea how to get started connecting the two.

I guess I could make a simple API for it, then just hit it when launching the app to populate the NSMutableArrays of questions/answers. Does that sound like a good approach? If not, how would you go about doing it (high-level)?

Upvotes: 1

Views: 394

Answers (2)

Dan Calinescu
Dan Calinescu

Reputation: 71

You're basically on the right track. You'd need to setup a basic HTTP RESTful API that preferably returns JSON. To hit the API via HTTP you can user ASIHTTPRequest as Michael suggested. To parse JSON in your iOS app, use the json-framework Create a couple of Model objects for yourself and load them from JSON, it would be easier to work with those rather then working with NSDictionary objects all the time. I'd setup a Quiz and a Question model at least. Hope it works out for you. Have fun!

Upvotes: 1

Michael Frederick
Michael Frederick

Reputation: 16714

You should make an API for the app to work with. Check out the ASIHTTPRequest library because it makes sending asynchronous http requests very easy. You will probably also want to take a look at a JSON serializer so that you can serialize your JSON (assuming you are using JSON) responses into NSArrays or NSDictionarys. A popular one is TouchJSON, which includes a serializer and a deserializer (for converting objects to/from JSON).

Upvotes: 1

Related Questions