简体   繁体   中英

Swift: How to save data of different types in a file

I want to save data including string, number, date and coordinate in a file, and then transmit the file to a server. How to do this using swift?

And I'd like to process these data from the server in the future. What type of file is better to save them?

If i am getting this right you can use NSData

First you have to create a dictionary like this

    var dictionary = [String:AnyObject]()
            dictionary["age"] = 13
            dictionary["name"] = "Mike"

Then you have to transform this dictionary into NSData using nsjsonserialization

if let data = NSJSONSerialization.dataWithJSONObject(dictionary, options:NSJSONWritingOptions(0), error:nil) as NSData? {


                    request.HTTPBody = data

                }

But this is always depend on what the server is able to understand

Hope i helped. Sorry for my english

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM