title: How to convert NSObject class object into JSON in Swift?
body: <p>I have </p>
  
  <pre><code>var  contacts : [ContactsModel] = []
  </code></pre>
  
  <p>and </p>
  
  <pre><code>class ContactsModel: NSObject
  {
     var contactEmail : String?
     var contactName : String?
     var contactNumber : String?
     var recordId : Int32?
     var modifiedDate : String?
  }
  </code></pre>
  
  <p>Now in contacts I'm having 6 values like</p>
  
  <p><a href="https://i.stack.imgur.com/czBAm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/czBAm.png" alt="enter image description here"></a></p>
  
  <p>Now i want to convert contacts into JSON how can i ? </p>
  
  <p>I tried </p>
  
  <pre><code>  var jsonData: NSData?
          do
          {
              jsonData = try NSJSONSerialization.dataWithJSONObject(contacts, options:NSJSONWritingOptions.PrettyPrinted)
          } catch
          {
              jsonData = nil
          }
    let jsonDataLength = "\(jsonData!.length)"
  </code></pre>
  
  <p>But it crashes the app.</p>
  
  <p>My issue is with manually converting in to a Dictionary one by one very time consuming it takes more than 5 minutes for 6000 records, So instead of that i want to convert directly model into JSON and send to server.</p>