a2 / MessagePack.swift

It's like JSON, but fast and small…and Swift! – msgpack.org[Swift]
http://msgpack.org
MIT License
283 stars 60 forks source link

Pack Dictionary #31

Closed sschizas closed 8 years ago

sschizas commented 8 years ago

Can you please provide me with an example how to pack a Dictionary<String, AnyObject> to msg-pack?

prcela commented 8 years ago
        let dic:[String:String] = [
            "phone": "123",
            "code": "090"
        ]

        var mpDic = [MessagePackValue:MessagePackValue]()

        for (key,value) in dic
        {
            mpDic[MessagePackValue(key)] = MessagePackValue(value)
        }

        let packed = MessagePackValue(mpDic)

        print(packed)
sschizas commented 8 years ago

Thank you very much for your reply. What if the dictionary is [String: AnyObject] ?

a2 commented 8 years ago

@n3trino In that case, you need to figure out what time of object each value is so you can convert it to the correct MessagePackValue case.

a2 commented 8 years ago

Although question was vague, it was answered. Closing until further discussion is needed.