尝试为模型对象分配值,但返回nil
我的模特:
struct Request:Mappable{
var id:String="" //
var origin:Location?
}
mutating func mapping(map: Map) {
id <- map["id"]//
origin <- map["origin"] //
}
struct Location :Mappable{
var address=Address()
mutating func mapping(map: Map) {
address <- map["address"]
}
var request=Request()
request.origin?.address.province?.id = "test" // assign nil
答案 0 :(得分:2)
假设您具有key1 = {key[0] for key in my_dictionary}
和Address
类型,如下所示,
Province
然后为省struct Address {
var province: Province?
}
struct Province {
var id: String?
}
分配一个值,您需要按如下所示设置id
,
request