- Home /
Local data saves on iOS (best practices)
I've been working on an iOS project based around using the GameCenter for turn based matches. As it stands everytime a player leaves the match the matches current state (in our case object positions) are parsed to a byte array then serialized as XML.
Really saving to XML is probably completely unnecessary as the same class which saves this data also opens and parses it. What would be the best format to save the data for extremely fast retrieval and saving. A few ideas I had were to save the byte array to a raw text document.
Any ideas? C.
You could save your byte array to player prefs. $$anonymous$$ight be easier. Not sure about speed, although I can't imagine it being slower than parsing an X$$anonymous$$L file.
I like that idea, would I have to serialise the by$$anonymous$$rray to a String, or does PlayerPrefs support raw by$$anonymous$$rrays... guess I'll find out myself haha!
it's hard to believe there could possibly be any performance issue imaginable here dude ?!?!!! have you actually tried it? How big is the X$$anonymous$$L file, are you talking gigabytes or something??????
Answer by whydoidoit · Jun 07, 2012 at 11:54 AM
I agree with @Fattie in the comments, but if you want to convert a byte array into a string without the XML (not sure what that would be doing that was too slow) you can use
var myString = Convert.ToBase64String(yourByteArray);
And to revert
var myByteArray = Convert.FromBase64String(myString);
What is your code to create the Byte Array? I am working on a game for ios and I am trying to use BinaryFormatter which is not working. Do you know of an alternative to create a byte array from a object?
Well you can use this. You could directly use
var data = UnitySerializer.Serialize(yourObject);
and
UnitySerializer.Deserialize<SomeClass>(data)
UnitySerializer had no idea that class existed! That's going to save some hours in the future :D Thanks @whydoidoit
You do need to install Unity Serializer from that link I provided...
@whydoidoit I'm jumping in with UnitySerializer tonight - can't wait ot share my experiences.
Your answer