I have two models:
class CellModel: StaticMappable {
static func objectForMapping(map: Map) -> BaseMappable? {
return nil
}
func mapping(map: Map) {
id <- map["id"]
title <- map["title"]
description <- map["description"]
}
private var id: Int
private var title: String
private var description: String
init(id: Int, title: String, description: String) {
self.id = id
self.title = title
self.description = description
}
}
and
class CellModelArray: StaticMappable {
var cells = [CellModel]()
static func objectForMapping(map: Map) -> BaseMappable? {
return nil
}
func mapping(map: Map) {
cells <- map["cells"]
}
}
I created a jsonString from object like this:
let jsonString = Mapper().toJSONString(rootModel, prettyPrint: false)
and json looks like this:
{"cells":[{"id":0,"title":"Header","description":"Description"},{"description":"Description","id":0,"title":"Header"},{"description":"Description","id":1,"title":"Header"},{"id":0,"title":"Header","description":"Description"},{"description":"Description","title":"Header","id":0}]}
Then I want to take this string and convert it back to the object, but when I try it like that:
var cells = CellModelArray()
cells = Mapper<CellModelArray>().map(JSONString: code) ?? CellModelArray()
it does not work and returns nil. Thank you for your help.