CristiC
CristiC

Reputation: 22698

What is the best way to update data for an iPhone app?

I am developing an application for iPhone and one part of it deals with a list of currencies and daily exchange rates. I am using SQLite to store all these rates.

Now I came to the part where I want to make the update part of my database with the new exchange rates.

The first thought was make a request to a server with a specific date and to read back an XML containing something like:

<date value="2010-10-04">
  <currency name="EUR" rate="xxx" />
  <currency name="USD" rate="yyy" />
  <currency name="GBP" rate="zzz" />
........
</date>
<date value="2010-10-05">
  <currency name="EUR" rate="xxx" />
  <currency name="USD" rate="yyy" />
  <currency name="GBP" rate="zzz" />
........
</date>

But now I was thinking isn't it better to make my own format, something like:

#|2010-10-04#EURxxx#USDyyy#GBPzzz#|2010-10-05#EURxxx#USDyyy#GBPzzz##

The separator will be #. Known that always the date takes 11 characters and starts with | and currency code takes 3 characters, I can search the rate until I will find a # sign.

Because I want to send as little data as I can I think this second approach will be better than the usual XML, even if I reduce the XML to:

<d v="2010-10-04">
  <c name="EUR" r="xxx" />
  <c name="USD" r="yyy" />
  <c name="GBP" r="zzz" />
........
</d>
<d v="2010-10-05">
  <c name="EUR" r="xxx" />
  <c name="USD" r="yyy" />
  <c name="GBP" r="zzz" />
........
</d>

What are your pro & cons for this?

Upvotes: 0

Views: 187

Answers (4)

Jimmeh
Jimmeh

Reputation: 21

CFPropertyList is pretty good if you're using PHP as your server-side language. Easy to integrate with your server code and has built in support in iOS (e.g. an NSDictionary can be created directly from a plist file).

Link: http://code.google.com/p/cfpropertylist/

Upvotes: 2

Tim
Tim

Reputation: 5421

JSON format would split the difference between a proprietary format and a standard format. It is somewhat less verbose than XML and has the flexibility and maintainability vodkhang rightly expects.

Upvotes: 3

Jordan
Jordan

Reputation: 21760

XML is easier to read and parse. Unless you're fetching a zillion currencies and daily rates a day, the # of bytes shouldn't be an issue.

Upvotes: 3

vodkhang
vodkhang

Reputation: 18741

The pros:

  • As you already stated, it is shorter, faster to retrieve.
  • Faster to parse as well

The cons:

  • If you develop the server side and the other developer on the mobile side, then he may get confused when there are no meanings

  • It is hard to scale when you have more and more attributes and if you delete or change some attributes, you have to go over all codes to change it.

Upvotes: 2

Related Questions