Jeremy Toeman
Jeremy Toeman

Reputation: 81

"Dynamic cast failure failure" from AnyObject? to Int

Nutshell - I'm trying to get a highscore out of a plist

Here's the code to read the data:

    var myOutput: AnyObject? = NSUserDefaults.standardUserDefaults().objectForKey("highscore")
    println(myOutput!)

This is successful and the result of the println is the correct data

    if myOutput != nil{
        highscore = myOutput! as Int
    }

This gives me a "Swift dynamic cast failure". From everything I've read this should be working, so any tips would be great.

Upvotes: 0

Views: 851

Answers (1)

Jeremy Toeman
Jeremy Toeman

Reputation: 81

Thanks to user2864740 got me on the right track. Correct solution is:

    if myOutput != nil{
        highscore = myOutput!.integerValue
    }

Upvotes: 1

Related Questions