我的taskModel类文件
import Foundation
import ObjectMapper
// Mappeable source code
public protocol Mappable {
init?(_ map: Map)
mutating func mapping(map: Map)
}
// Conform to the Mappable protocol
class taskModel: Mappable {
var taskid: Int = 0
var parentId: Int = 0
var taskname : String = ""
var createdBy : String = ""
var startDate : String = ""
var taskStatus : String = ""
var Color : String = ""
init(){
}
// MARK: Mappable
required init?(_ map: Map) {
// subClasses must call the constructor of the base class
// super.init(map)
}
// Mappable
func mapping(map: Map) {
taskid <- map["username"]
parentId <- map["age"]
taskname <- map["weight"]
createdBy <- map["arr"]
startDate <- map["dict"]
taskStatus <- map["best_friend"]
Color <- map["friends"]
}
}
我的视图控制器
let taskJson = "{\"\"success\": true,\"\"messages\": \"successfully\",\"\"data\": [\"\"{\"\"\"\"taskId\": \"264\",\"\"\"\"parentId\": null,\"\"\"\"taskName\": \"order\",\"\"\"\"createdBy\": \"xyz\",\"\"\"\"assignedto\": \"xyz\",\"\"\"\"startDate\": \"23/11/2016\",\"\"\"\"taskStatus\": \"Open\",\"\"\"\"Color\": \"#6bea66\"\"\"}\"]}";
let repo = Mapper<taskModel>().map(taskJson)
我尝试导入ObjectMapper,然后它显示,
我会要求你请给予我一个完整的例子,如果我做的错误的地方。
1条答案
按热度按时间fykwrbwg1#
I get this from here
更新Pods和清理构建文件夹解决了我的问题。希望这对你有帮助!!