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):

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:

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…

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:

This may give you some ideas.