thoughts on saveLocalData

hey folks,
I somewhat guessed it but now tested and found out, that saveLocalData saves information under a “global” key. Which means, saving information from class instances(!), causes the key to get overriden!

What are your thoughts - how could this problem be solved in an elegant way?
My first idea would be to save all instances in a table and save this table to LocalData. Any other ideas? Any suggestions how to approach this?

maybe prefix the save key with the instance name/id

If you want to go the table route then the following contains some functions to serialise your table to a string (so that you can save it in LocalData):

http://codeatuts.blogspot.com.au/2012/09/tutorial-16-convert-string-to-table-and.html

An extension of @Ignatz’s suggestion would be to have the key as an instance variable in your class.

I also did a simple File Manager to play around with the various data types, which might give you some ideas:

http://codeatuts.blogspot.com.au/2012/09/tutorial-17-simple-file-manager-for.html

how could I create a dynamic prefix, which stays for each instance the same, even after reload the app?
I tried tostring(self), but this string changes with each restart of the app…
But I dislike the idea of passing a string manually. I want it to be automated.

I just cant find a unique, but at the same time permanent, automatically generated, prefix. tried tostring(self) and other things, but they all change after app restart. I need something different… relyable… any ideas?

In the meantime, watch my experiment, which depends on what I’m asking for…


http://youtu.be/41ALxB5p0m4

I think what you are after is a uuid generator. In Objective C this is very easy:

- (NSString *)uuid
{
    //  Generate a uuid to use as the unique key.
    
    return [[NSUUID UUID] UUIDString];
}

In Lua you are going to have to roll your own. Have a look at: http://developer.coronalabs.com/code/uuidguid-string-generator-coronalua

This may give you some ideas.