I don't know about Swift, but in Objective-C, couldn't you use something like NSKeyedArchiver for serializing a complex object graph to a byte string? It's not safe if you don't trust the input, but if you do, I'm not sure why you'd go to the effort of reinventing this particular wheel, besides it being fun. Though maybe the serialization and deserialization are not the interesting parts here.