2016-08-20 33 views
1
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「。我試過鑄造,它仍然是行不通的「不能指定'Int'類型的值來鍵入'Uint'」

回答

1

你提到你的努力鑄造,我假定你的意思是這樣的:

stripCard.expMonth = themonth as! UInt 

但鑄造將無法工作,因爲它們是完全不同的類型。相反,嘗試轉換使用UInt的初始化程序,需要一個Int,如下所示:

stripCard.expMonth = UInt(themonth) 
相關問題