1

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?

Wenyi Li
  • 35
  • 1
  • 4

1 Answers1

1

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