I have
var contacts : [ContactsModel] = []
and
class ContactsModel: NSObject
{
var contactEmail : String?
var contactName : String?
var contactNumber : String?
var recordId : Int32?
var modifiedDate : String?
}
Now in contacts I have 6 values, for example

Now I want to convert contacts to JSON, how can I?
I tried
var jsonData: NSData?
do
{
jsonData = try NSJSONSerialization.dataWithJSONObject(contacts, options:NSJSONWritingOptions.PrettyPrinted)
} catch
{
jsonData = nil
}
let jsonDataLength = "\(jsonData!.length)"
But this leads to a crash of the application.
My problem is to manually convert to the dictionary one by one a lot of time, it takes more than 5 minutes for 6000 entries, so instead I want to convert the model directly to JSON and send it to the server.
source
share