I’m pretty new to iPhone development – so apologies if this is a dumb question 😉
I have a bunch of data for mapping a pre-calculated relationships between values
e.g.
Mapping light input to power output for a solar panel.
One scale is fixed and can be easily calculated (i.e. it goes up in steps of 0.1 and has a known start and end point)
0.0 – 80.0
The other scale is defined by some data that I have in text format:
9.80293622028191E+0000, 9.82985159414126E+0000, 9.85682155471754E+0000, 9.88384617060865E+0000, 9.91092551045114E+0000, 9.93805964292038E+0000, 9.96524863673053E+0000, 9.99249256063480E+0000, 1.00197914834255E+0001, 1.00471454739344E+0001, 1.00745546010324E+0001 etc
I can use this on the phone to plot the lines for different variables.
The total data in text format is about 4mb (about 32kb per data line)
The question is – how best to store that array of float values such that I can easily update it – and also easily load it up for display?
I don’t ever need to pick out a single value from it – I’ll always need the whole list for a given line – so it seems to make sense to store it as a single data object. I could save it as text to a file and then overwrite the file when I want to update it. However – I’m going to need a SQL lite db for other data and this seems more sensible for storing data.
Using the float data type in SQL seems to be quite a heavy way to do it – as I’ll always want a complete set of values for a line so every select will be a join and (I’ll have to store the order info so I can get them back in the right order)
Does it makes sense to push the whole array into a string and store it as Text? Or is there a decent way to serialize an NSArray into a blob field and reconstruct it later?
—–EDIT———-
It turns out that a few thousand rows of floats in the SQLite db is terribly slow on the phone itself. It’s ok in the simulator, but can take 20 seconds or so to load on the phone. To get round this I’ve put this data into flat text files and I convert to floats as I load it into an NSArray.
You can serialize/unserialize your Array calling:
and
However, I would recommend either
1) storing your Array into a file (writeToFile, arrayWithContentsOfFile)
or better
2) writing them into your existing SQLite-Database value by value. If I got you right, you don’t need any joins. Just fetch your values using: