let expdate = NSUserDefaults.standardUserDefaults().objectForKey("expiration") as! NSDate
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Day , .Month , .Year], fromDate: expdate)
var theyear = components.year
var themonth = components.month
stripCard.expMonth = themonth
stripCard.expYear = theyear
在最后两行我收到错误:"无法分配类型' Int'输入" Uint'。我已经尝试过施法,但仍然无法工作
答案 0 :(得分:4)
你提到你试过施法,我认为你的意思是:
stripCard.expMonth = themonth as! UInt
但是铸造不起作用,因为它们是完全不同的类型。相反,尝试使用UInt的初始化器进行转换,该初始化器采用Int,如下所示:
stripCard.expMonth = UInt(themonth)