hi Jim,
certainly, the right answer is "it depends ..." on what you're saving.
using JSON is indeed easy, but one thing that potentially inflates file size is saving many objects of the same type where the length of variable names is a little long.
example: if you have structs/objects with variable names such as lengthOfGame
, numberOfPlayers
, crowdSize
, finalScore
, matchWentIntoOvertime
, and so forth, every object encoding will have these strings as idenitifers in the JSON. if you have a few thousand of these, that's a problem (not so much for speed of encoding/decoding, but for JSON filelength).
so, do some testing with JSON. but use CodingKeys to control the names actually written to JSON, as in this example that i have used in my code to change longer, readable variable names into condensed identifiers for JSON.
enum CodingKeys: String, CodingKey {
case bidLevel = "bLvl"
case dealerIndex = "dlrIdx"
case declarerIndex = "dclIdx"
case doubledState = "dbl"
case handIndex = "hIdx"
case playerIDs = "pIDs"
case previousHandIndex = "pIdx"
case roundIndex = "rIdx"
case score = "scr"
case sessionID = "sID"
case suit = "st"
case tricksTaken = "tTakn"
case vulnerable = "vul"
case vulnerabilityStyle = "vulStl"
}
then test again. my recollection is the i was decreasing file size by as much as 40% just with this alone on about 2500 objects. (i suppose changing the coding keys to numbers would help even more.)
hope that helps,
DMG