title: Passing predefined Object to Alamofire
body: <p>I'm trying to pass a Object in Alamofire but no success. Following is my object</p>
  
  <pre><code>class MyRequestObject : NSObject, Codable {
  
  var myData : MyDataType?
  var simpleString : String?
  
  }
  </code></pre>
  
  <p>MyRequestObject is a nested object with 3-4 nested objects and I'm filling all the objects at some point before finally getting to this VC where I'll make the API Call. Now When I get to the final VC, i have the Object filled with data and ready to send with the Request but Alamofire won't accept the object in Parameters. This is what i'm trying to do</p>
  
  <pre><code>    let parameters = [
          "RequestID" : self.rID,
          "RequestTime" : "self.rTime",
          "RequestObject" : myRequestObject
      ]
  </code></pre>
  
  <p>getting this error in log <code>Invalid type in JSON write FOO.MyRequestObject</code></p>
  
  <p>while if I recreate the complete object in <code>parameters</code> like this (just Shorter object for reference)</p>
  
  <pre><code>        let parameters = [
          "RequestID" : self.rID,
          "RequestTime" : self.rTime,
          "RequestObject" : [
              "key" : self.SomeValue,
              "key" : self.SomeValue,
              "key" : self.SomeValue,
              "seconNestedObj"[
                  "key" : self.SomeValue,
                  "thirdNetedObj" : [
                      "key" : self.SomeValue,
                      "key" : self.SomeValue
                  ]
              ]
          ]
      ]
  </code></pre>
  
  <p>it works. BUT I don't want to recreate everything here. Is there any way to do it or I'll have to do the recreation thing here. </p>
  
  <p>I've done something similar in Android and it worked and I was expecting something similar here in swift.</p>
  
  <p>Can someone please tell me how can I do it?</p>