在模型函数中初始模型失败

时间:2016-12-02 10:27:12

标签: ios swift model

获取模型信息失败。在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!
}

哪里错了?我找不到。

0 个答案:

没有答案