具有ObjectMapper错误的模型类从初始化程序返回而不初始化所有存储的属性

时间:2017-10-26 09:06:18

标签: ios alamofire xcode9 swift4 objectmapper

我收到错误:从初始化程序返回而未初始化init()上的所有存储属性

import Foundation
import ObjectMapper

struct ProductGroup: Mappable {

var group_title: String
var group_type :String
var products: Array<Products>


  init?(map: Map) {


}



 mutating func mapping(map: Map) {
    self.group_title     <- map["group_title"]
    self.group_type <- map["group_type"]
    self.products   <- map["products"]
}
}

2 个答案:

答案 0 :(得分:1)

尝试将所有属性设为可选或初始化

参考文档https://github.com/Hearst-DD/ObjectMapper

我还附加了一个来自Document的屏幕快照,可以帮助您解决问题:

enter image description here

答案 1 :(得分:0)

如果你的变量是 var &amp; 不是可选的然后您必须初始化它,如果您不想这样做,那么您必须要应用 var 作为可选。

如下所示

var group_title: String?
var group_type :String?
var products: Array<Products>?