title: Swift 3 - Declaring a simulated JSON as a response from a server
body: <p>I'm making an application with swift 3.0. But I have a problem, because in the API REST still have not implemented the service, I'm creating a simulated JSON to continue working. But the problem as you will see at the end of all the explanation in the image is that I do not know how to declare a JSON "-.- .... Basically the program will make a call to the server and it will respond with a JSON (now I pass it "the simulated" you will see it in the code). And with that JSON maps it with ObjectMapper to some models (that I pass the code) so that in the end the application has an object.</p>
  
  <p><a href="https://i.stack.imgur.com/Qq09f.png" rel="nofollow noreferrer">Error declaring Simulated JSON</a></p>
  
  <p>These are the three models I have to map the JSON when it will come from the server or in this case, the simulated JSON.</p>
  
  <p>The first is "LegendEntriesModel":  </p>
  
  <pre><code>import Foundation
  import ObjectMapper
  import AlamofireDomain
  
  class LegendEntriesModel: Mappable {
  
  
  fileprivate var _id_snapshot:     String?
  fileprivate var _date:            String?
  fileprivate var _deliverables:    [DeliverablesModel]?
  
  
  
  init(){}
  
  required init?(map: Map) { }
  
  func mapping(map: Map) {
      self.id_snapshot      &lt;- map["id_snapshot"]
      self.date             &lt;- map["date"]
      self.deliverables     &lt;- map["deliverables"]
  }
  
  var id_snapshot: String {
      get {
          if _id_snapshot == "" {
              _id_snapshot = ""
          }
          return _id_snapshot!
      }
      set {
          _id_snapshot = newValue
      }
  }
  
  
  var date: String {
      get {
          if _date == "" {
              _date = ""
          }
          return _date!
      }
      set {
          _date = newValue
      }
  }
  
  
  var deliverables: [DeliverablesModel] {
      get {
          if _deliverables == nil {
              _deliverables = []
          }
          return _deliverables!
      }
      set {
          _deliverables = newValue
      }
  }
  
  
  
  //MARK: RELEASE MEMORY BETWEEN OBJECT AND API REST (BROKE DEPENDENCIS)
  func copy()-&gt;LegendEntriesModel {
  
      let legendEntriesModel  = LegendEntriesModel()
  
      legendEntriesModel.id_snapshot   = self.id_snapshot
      legendEntriesModel.date          = self.date
      legendEntriesModel.deliverables  = copyDeliverables()
  
      return legendEntriesModel
  }
  
  func copyDeliverables() -&gt; [DeliverablesModel]{
      var newArray: [DeliverablesModel] = []
      for item in deliverables {
          newArray.append(item.copy())
      }
      return newArray
  }
  }
  </code></pre>
  
  <p>The second on is "DeliverablesModel"</p>
  
  <pre><code>import Foundation
  import ObjectMapper
  import AlamofireDomain
  
  class DeliverablesModel: Mappable {
  
  
  fileprivate var _id:              String?
  fileprivate var _type:            String?
  fileprivate var _url_layer:       String?
  fileprivate var _options:         OptionsDeliverablesModel?
  
  
  
  init(){}
  
  required init?(map: Map) { }
  
  func mapping(map: Map) {
      self.id               &lt;- map["id"]
      self.type             &lt;- map["type"]
      self.url_layer        &lt;- map["url_layer"]
      self.options          &lt;- map["options"]
  }
  
  var id: String {
      get {
          if _id == "" {
              _id = ""
          }
          return _id!
      }
      set {
          _id = newValue
      }
  }
  
  
  var type: String {
      get {
          if _type == "" {
              _type = ""
          }
          return _type!
      }
      set {
          _type = newValue
      }
  }
  
  
  var url_layer: String {
      get {
          if _url_layer == "" {
              _url_layer = ""
          }
          return _url_layer!
      }
      set {
          _url_layer = newValue
      }
  }
  
  var options: OptionsDeliverablesModel {
      get {
          if _options == nil {
              _options = OptionsDeliverablesModel()
          }
          return _options!
      }
      set {
          _options = newValue
      }
  }
  
  //MARK: RELEASE MEMORY BETWEEN OBJECT AND API REST (BROKE DEPENDENCIS)
  func copy()-&gt;DeliverablesModel {
  
      let deliverablesModel  = DeliverablesModel()
  
      deliverablesModel.id         = self.id
      deliverablesModel.type       = self.type
      deliverablesModel.url_layer  = self.url_layer
      deliverablesModel.options    = self.options
  
      return deliverablesModel
  }
  }
  </code></pre>
  
  <p>And the last one is "OptionsDeliverablesModel":</p>
  
  <pre><code>import Foundation
  import ObjectMapper
  import AlamofireDomain
  
  class OptionsDeliverablesModel: Mappable {
  
  
  fileprivate var _type:                 String?
  fileprivate var _max_range:            Float?
  fileprivate var _min_range:            Float?
  fileprivate var _title:                String?
  fileprivate var _initial_max_value:    Float?
  fileprivate var _initial_min_value:    Float?
  fileprivate var _id:                   String?
  
  
  
  init(){}
  
  required init?(map: Map) { }
  
  func mapping(map: Map) {
      self.type                       &lt;- map["type"]
      self.max_range                  &lt;- map["max_range"]
      self.min_range                  &lt;- map["min_range"]
      self.title                      &lt;- map["title"]
      self.initial_max_value          &lt;- map["initial_max_value"]
      self.initial_min_value          &lt;- map["initial_min_value"]
      self.id                         &lt;- map["id"]
  }
  
  var type: String {
      get {
          if _type == "" {
              _type = ""
          }
          return _type!
      }
      set {
          _type = newValue
      }
  }
  
  
  var max_range: Float {
      get {
          if _max_range == 0 {
              _max_range = 0
          }
          return _max_range!
      }
      set {
          _max_range = newValue
      }
  }
  
  var min_range: Float {
      get {
          if _min_range == 0 {
              _min_range = 0
          }
          return _min_range!
      }
      set {
          _min_range = newValue
      }
  }
  
  
  var title: String {
      get {
          if _title == "" {
              _title = ""
          }
          return _title!
      }
      set {
          _title = newValue
      }
  }
  
  var initial_max_value: Float {
      get {
          if _initial_max_value == 0 {
              _initial_max_value = 0
          }
          return _initial_max_value!
      }
      set {
          _initial_max_value = newValue
      }
  }
  
  var initial_min_value: Float {
      get {
          if _initial_min_value == 0 {
              _initial_min_value = 0
          }
          return _initial_min_value!
      }
      set {
          _initial_min_value = newValue
      }
  }
  
  var id: String {
      get {
          if _id == "" {
              _id = ""
          }
          return _id!
      }
      set {
          _id = newValue
      }
  }
  
  
  
  
  //MARK: RELEASE MEMORY BETWEEN OBJECT AND API REST (BROKE DEPENDENCIS)
  func copy()-&gt;OptionsDeliverablesModel {
  
      let optionsDeliverablesModel  = OptionsDeliverablesModel()
  
      optionsDeliverablesModel.type               = self.type
      optionsDeliverablesModel.max_range          = self.max_range
      optionsDeliverablesModel.min_range          = self.min_range
      optionsDeliverablesModel.title              = self.title
      optionsDeliverablesModel.initial_max_value  = self.initial_max_value
      optionsDeliverablesModel.initial_min_value  = self.initial_min_value
      optionsDeliverablesModel.id                 = self.id
  
      return optionsDeliverablesModel
  }
  }
  </code></pre>
  
  <p>With these three "Models" are what I can map the JSON inside the class DAO, but here is the problem, because I do not know how to pass my JSON that I have simulated.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>import AlamofireDomain
  import Alamofire
  import ObjectMapper
  
  class DeliverablesLegendDAO : SimpleDAO {
  
  var deliverables = Dictionary&lt;String, Any&gt;()
  
  deliverables = [{"legendEntries": [{"id_snapshot": "123","date": "2016-10-20","deliveries": [{"id": "12","type": "RGB","url_layer":"topp:states","options": [{"type": "range","max_range": 100,"min_range": 0,"title": "Option RGB","initial_max_value": 100,"initial_min_value": 0,"id": "depth"}]}]}]}]
  
  func snapshots(_ parameters: String,
             callbackFuncionOK:    @escaping (LegendEntriesModel)-&gt;(),
             callbackFunctionERROR: @escaping (Int,NSError)-&gt;()) {
  
  
  
      Alamofire.request(parameters,
                        method: .post,
                        encoding: JSONEncoding.default)
          .responseJSON { response in
              if response.result.isSuccess{
                  if let status = response.response?.statusCode {
                      switch(status){
                      case 200:
                          let value = response
                          let legendEntries = Mapper&lt;LegendEntriesModel&gt;().map(JSONObject: value)
                          callbackFuncionOK(legendEntries!)
  
                      default:
                          break
                      }
                  }
              }
  
              else {
                  var statusCode = -1
                  if let _response = response.response {
                      statusCode = _response.statusCode
                  }
                  var nsError: NSError = NSError(domain: Constants.UNKNOWN_HTTP_ERROR_MSG,
                                                 code: Constants.UNKNOWN_HTTP_ERROR_ID,
                                                 userInfo: nil)
                  if let _error = response.result.error {
                      nsError = _error as NSError
                  }
                  callbackFunctionERROR(statusCode,nsError)
              }
  
      }
  }
  
  }
  </code></pre>
  
  <p>As you can see in the image, I am declaring my simulated JSON wrong and then map it with "LegendDeliveriesModel" to an object. How can I do it?</p>
  
  <p><a href="https://i.stack.imgur.com/2l1un.png" rel="nofollow noreferrer">Error declaring simulated JSON</a></p>
  
  <p>If you need anything else, tell me. I repeat, the problem is in the JSON simulated statement that I do not know how to pass it to DAO and that it maps it.</p>