On Wednesday, October 31, 2012 1:16:03 AM UTC+1, Bora Celik wrote:
Yeah I also use GCD as recommended above but in general, is it a good idea to store large datasets on the phone? I first started doing this, importing lots of data on the phone from another API. Maybe I wasn't doing it the most optimal way but the app started acting quite unstable during these data transfers despite the asynchronous processing as it was just taking a long time.
In the end I decided to move the heavy data storage bits to the API and not use the iOS app for storing large amounts of data.
Todays smartphones are able to deal with multi-megabyte databases with ease. I know of an app, which holds all flights worldwide in a database and works just great. So it would be a design choice of the app. Does it make sense to have the data available offline? I built a cinema listing app (
http://bit.ly/kpilot) which uses offline data for movies and listings. If this was an app for buying movie tickets online having the data offline would probably not make much sense, because the central idea of the app - buying tickets online - would require an online connection already.
Anyways, my data is up to 10.000 records, and changes on a daily basis. I worked on different solutions for fetching and storing the data. In the end I came up with this solution, which was outperforming everything else I tried by far:
- prepare the dataset on the server, producing a JSON response
- The JSON response stores each record in an array notation, because this way it can be directly consumed by a native API without reordering or rebuilding
- On the device I store the data in and retreive it from a sqlite database. Coredata was not good enough for me, because using it involved rebuilding several objects per record, resulting in a >200% overhead.
- If possible, the data block does not contain the full dataset, but a "diff" to minimize the data transfer rate.
- run a blocking HTTP request in the background (GCD), which fetches the data block, parses it, opens a db transaction, and passes it into the db.
This works perfectly, and I think it really adds value to the app, because it has all data available all the time. Storing a full update takes ~5 secs on an iPhone 4, storing a daily update often takes less than 1 sec on an iPhone 4, and is done in the background anyways.
Not using Coredata, however, means not having data bindings and such available. On the other hand using a sqlite database is potentially portable, while using Coredata is not.
/eno
---
Follow me on twitter: @radiospiel