Swift – How to Convert Int32 to Int

core-dataintswifttype-conversion

It should be easy but I can only find the reverse conversion.
How can I convert Int32 to Int in Swift?
Unless the problem is different?

I have a value stored in Core Data and I want to return it as an Int.

Here is the code I am using, which does not work:

func myNumber () -> Int {
    var myUnit:NSManagedObject
    myUnit=self.getObject(“EntityName”) // This is working.

    return Int(myUnit.valueForKey(“theNUMBER”)?.intValue!)
 }

Best Answer

Am I missing something or isn't this ridiculously easy?

let number1: Int32 = 10
let number2 = Int(number1)
Related Question