Transmission Line Noise

Han­dling and Stor­ing Data in iOS

Mon, Aug 12, 2013
AFNetworking Core Data Databases/Datastores FMDB iCloud iPhone Miscellaneous Parse Plist Rem Objects SQlite Stackmob Windows Azure


My expe­ri­ence over the last few years has been that of con­nect­ing to one or other of the data­bases web devel­op­ers are accus­tomed to con­nect­ing to. So MySQL Post­greSQL, Redis, Mongo etc.

In the early days access was by a con­nec­tion and then writ­ing sql code to extract the data and so forth. Lat­terly it has been in an OO method using an ORM or at least some form of library and abstrac­tion layer. Sim­pler and more effi­cient, or slower and more com­plex depend­ing on your point of view.

How­ever mov­ing to mobile means i need at the very least to rethink the the process and prob­a­bly to change my way of think­ing and work­ing. The first and most obvi­ous changes are con­nec­tiv­ity and storage.

Con­nec­tiv­ity & Storage

Unlike the web appli­ca­tions a mobile device has lim­ited con­nec­tiv­ity & in some case more expen­sive con­nec­tiv­ity and has lim­ited stor­age. It may seem blind­ingly obvi­ous but there are two way iOS devices connect

  • Cel­lu­lar
  • WiFi

Unless some­one has an unlim­ited data plan then cel­lu­lar con­nec­tion for data can be expen­sive, use up the sub­scribers allowance and also be quite slow, espe­cially at cru­cial times or when con­nec­tions are poor etc. WIFI is often free, in the home, in Star­bucks, a good tip if you really want a fast con­nec­tion is to use an Apple store. But some­times peo­ple pay for wifi, on trains, most hotels these days so again an eye needs to be kept on how much is down­loaded and when.

gen­eral size of iOS appli­ca­tions and Apple restriction

Stor­age Options

This is not a detailed expla­na­tion of these types of stor­age. For that you need to look fur­ther doing your own research

  • Plist — Apples native prop­erty lists. Essen­tially xml files but opti­mised for O SX and iOS. Exten­sively used and for smaller amounts of data very effi­cient. Apart from any­thing else as they are so embed­ded in Apple pro­gram­ming culk­ture they are solid and reli­able and well known. So a ques­tion in an Apple Forum or at Stack Over­flow will almost cer­tainly be answered. - See more at Apple
  • XML File — Plain XML file. If you are cre­at­ing it your­self it would be bet­ter use a Plist. But it might be some­thing you are extract­ing from a feed with a rest call
  • File — Other than xml you may also be reciev­ing a file back in another for­mat. The most likely being JSON. This is a very pop­u­lar and light­weight form of data trans­mis­sion and often used as a replace­ment for xml. Of course the file could be of any for­mat that you can parse and of your own devising
  • SQLite - is an inter­est­ing ani­mal and worth you spend­ing some time on read­ing up — see here — in its own words “SQLite is a soft­ware library that imple­ments a self-contained, server­less, zero-configuration, trans­ac­tional SQL data­base engine. SQLite is the most widely deployed SQL data­base engine in the world. The source code for SQLite is in the pub­lic domain.” So it’s a sin­gle file with the pro­gram and the data in it. You plonk it on you iPhone/iPad and access it with SQL com­mands and that’s it. To back it up make a copy of the file. To give a copy of the data to another device, copy the file. SQLite can be used as any SQL data­base with stan­dard queries. How­ever it is recomended to use a wrap­per such as FMDB to make life a bit eas­ier (see below).
  • Core Data — This is not a data­base or a data­s­tore but as Apple says “The Core Data frame­work pro­vides gen­er­alised and auto­mated solu­tions to com­mon tasks asso­ci­ated with object life-cycle and object graph man­age­ment, includ­ing per­sis­tence.”. So if you have used and ORM in Web pro­gram­ming it is like that. Sim­plis­ti­cally it is a wrap­per around any data­s­tore you use and allows you to access that data­s­tore with a stan­dard set of com­mands. If you read more and listed to the tech pod­casts you will get vary­ing opin­ions of Core­Data from bril­liant to awful. I shall post a sep­a­rate pice on this range of opin­ions in the near future.
  • iCloud — Again not a data­s­tore or data­base but Apples way of trans­fer­ing data in an appli­ca­tion between that appli­ca­tion on dif­fer­ent devices (all Apple devices). e.g. Your cal­en­dar on your iPhone. You add all sorts of data to it and then pick up you iPad or go onto your iMac and the data is not there. So you could reen­ter it all but sounds a bit silly and mas­sively inef­fec­tive. How­ever, if you switch iCloud on then via Apples servers (and the Amer­i­can secret ser­vice no doubt) your data will be synced between all you devices.

Third Party Libraries

  • AFNet­work­ing — (free) a library wrap­ping Apple foun­da­tion classes that just makes life eas­ier. Well sup­ported and a thriv­ing com­mu­nity worth a look here
  • FMDB - (free) more focused and is a wrap­per round SQLite look here
  • Rem Objects - (paid for) well estab­lished com­pany (2002) pro­vid­ing a range of prod­ucts in the mobile space both cross plat­form and cross lan­guage. Their prod­ucts are all charged for but at the point you need them, and they are not a small devel­oper type prod­uct, the cost is insignif­i­cant to the money you can no doubt save. here.

Cloud Ser­vices

There are two types of cloud ser­vices. Those like Ama­zon Web Ser­vices — AWS that pro­vide servers and data­bases (putting it very sim­ply) in the cloud and those that as well as pro­vid­ing servers and data­bases also pro­vide spe­cific ser­vices geared to the mobile market

  • Win­dows Azure - (paid for) cloud ser­vices from Microsoft.x here.
  • Parse — Will store app data in the cloud, run app code in the cloud and will also man­age push noti­fi­ca­tions. Parse were an inde­pen­dent com­pany bu have recently been acquired by Face­book. Parse not sur­pris­ingly offer social inte­gra­tion prob­a­bly heav­ily with Face­book but is that is your thing then that is a ben­e­fit. Parse offers free plans up to a cer­tain amount of use­age after which you start pay­ing. See more here
  • Push​.io — are sim­i­lar to Parse but do not have a free entry level plan. More here
  • Stack­mob — are sim­i­lar to Parse and Push but do have a free entry level plan. More here