AtkinsonCM
AtkinsonCM

Reputation: 376

How to get data into Core-Data from an SQL Database?

I'm about to start an iOS project that requires pulling user's data from an SQL Database and viewing it within the App. Before I begin I'm looking for conformation that I'm taking the right (best) route.

My Plan:

  1. App starts on login page (app will display data from another service)
  2. App uses AFNetworking to post request to web service
  3. Web service gets user data from SQL Database and sends back JSON
  4. App uses JSONKit to parse the feed and load into Core-Data
  5. App uses info from core-data to populate UI

Does this seem like an appropriate way to get the info into Core-Data from SQL? Any suggestions for doing things differently?

Thanks.

Upvotes: 3

Views: 995

Answers (2)

kubi
kubi

Reputation: 49354

Are you receiving the response from the web server in JSON? If so, the fact that the server is using an SQL database is immaterial. What you need to know is how to parse JSON for inclusion in a core data store. Cocoa is my Girlfriend has a pretty good tutorial up.


To answer your comment, here's what I've done.

  1. Display a login screen. The login credentials should be stored in the keychain for security. I've used SSKeychain for this.
  2. To handle sending and receiving data from a web request your best option is to use a pre-built library. I've always used ASIHTTPRequest, but since it is no longer under active development, you should probably look around a bit before you commit to anything. I'm sure there are nicer and cleaner libraries out there.
  3. You need to parse the JSON responses. I'm a fan of JSONKit. It's very fast, very easy to use, very robust.

Pulling data out of the core data store and displaying it in the interface will be no problem for you. If you create a new project in Xcode most of the setup will be done for you.

Now, there are a lot of projects out there that attempt to combine web requests, json parsing and core data loading into one framework. I've tried to use a few of these and haven't had much luck. The ones I've tried haven't been robust and very difficult to debug. Setting up your own request/parse/load code is not difficult at all, just a bit time consuming.

Upvotes: 3

Pfitz
Pfitz

Reputation: 7344

I am sure that there are a lot os ways to make implement this problem. Your solution is one of the popular solutions I guess but you could connect to the DB via a socket and talk with the database directly e.g. Going over a port 80 web site has the advantage that the possibility of some kind of firewall blocking the communication is very low. I would solve this kind of problem the same way I guess.

Upvotes: 0

Related Questions