title: Create JSON Object from Class in Swift
body: <p>I'm pretty new to iOS development and Swift (so please bear with me).  I have a class object defined like this:</p>
  
  <pre><code>class LocationPoint {
      var x: Double
      var y: Double
      var orientation: Double
  
      init(x: Double, y: Double, orientation: Double) {
          self.x = x
          self.y = y
          self.orientation = orientation
      }
  }
  </code></pre>
  
  <p>In my delegate, I create an instance of the class and append it to an array (declared outside the delegate):</p>
  
  <pre><code>var pt = LocationPoint(x: position.x, y: position.y, orientation: position.orientation)
  self.LocationPoints.append(pt)
  </code></pre>
  
  <p>So far so good. I can show the array values in a textview object in my viewcontroller and it is definitely adding values each time it updates.</p>
  
  <p>Now, what I'd like to do is after the array count reaches a limit (say 100 values) then package it up as a JSON object and send it to a webserver using a HTPP Request.  My initial thoughts were to use <a href="https://github.com/SwiftyJSON/SwiftyJSON" rel="nofollow">SwiftyJSON</a> and <a href="https://github.com/Alamofire/Alamofire" rel="nofollow">Alamofire</a> to help with this...but if I try to break the problem down into smaller parts then I need to:</p>
  
  <ol>
  <li>Create JSON object from array of LocationPoints</li>
  <li>Create HTTP request to send JSON packet to a webserver</li>
  </ol>
  
  <p>Right now, I'm just trying to solve step 1, but can't seem to get started.  I've used CocoaPods to install both pods (SwiftyJSON and Alamofire) but I don't know how to actually use them in my viewcontroller.swift file.  Can anyone provide some guidance on how to create a JSON object from a custom class structure?</p>