user1232690 user1232690 - 1 month ago 9
Swift Question

Could not cast value of type 'Swift.UInt32' to 'Swift.Int'

In Tests project I've got extensions with some test helper functions. Like this:

extension Employee {
static func mockDict() -> Dictionary<String, Any>! {
return ["ID": arc4random() % 1000,
"FirstName": "Employee First Name",

(I've stripped unnecessary code). I've got problem accessing ID from this dictionary for some yet unknown reason. I've got SIGABRT 6 when casting

employeeDict["ID"] as! Int

Xcode debugger console also don't like this particular integer:


Strings work fine. Have you encountered such problem? Any ideas?


Try this:

let a = employeeDict["ID"] as! UInt32
let number = Int(a)

Now you can use number to perform any action.