Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot assign value of type 'Int' to type 'Uint' "

Tags:

swift

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

On the last 2 lines I'm getting an error: "Cannot assign value of type 'Int' to type "Uint'. I've tried casting and it still won't work

like image 202
user3015221 Avatar asked Aug 20 '16 02:08

user3015221


1 Answers

You mentioned that you tried casting, I assume you mean something like:

stripCard.expMonth = themonth as! UInt

But casting won't work because they are completely different types. Instead, try converting using UInt's initializer that takes an Int, like this:

stripCard.expMonth = UInt(themonth)
like image 119
Daniel Hall Avatar answered Sep 24 '22 05:09

Daniel Hall