获取模型信息失败。在initFormListModelWithDic
看到我的breckpoint线:
模型初始方法是这样的:
import UIKit
class FormListModel: NSObject {
var total:String = "0.00"
var commission:String = "0.00"
var year:String = ""
var month:String = ""
class func initFormListModelWithDic(_ dic: [String:Any]) -> FormListModel {
let model:FormListModel = FormListModel.init()
model.total = UtilSwift.getStrFromAny(dic["total"] ?? "")
model.year = UtilSwift.getStrFromAny(dic["year"] ?? "")
model.month = UtilSwift.getStrFromAny(dic["month"] ?? "")
model.commission = UtilSwift.getStrFromAny(dic["commission"] ?? "")
return model // breakpoint here, po model.total -> "0.00" here I lldb the information. see below.
}
}
在lldb
:
(lldb) po model.year
""
(lldb) po dic
▿ 3 elements
▿ 0 : 2 elements
- .0 : "total"
- .1 : 0.00
▿ 1 : 2 elements
- .0 : "year"
- .1 : 2016
▿ 2 : 2 elements
- .0 : "month"
- .1 : 12
(lldb) po dic["total"]
▿ Optional<Any>
在UtilSwift
:
class func getStrFromAny(_ any:Any) -> String {
let ret = any as? String ?? String(any as? String ?? "")
return ret!
}
哪里错了?我找不到。