Cannot force unwrap value of non-optional type: Avoid "Optional()"

You've already unwrapped playerDic in the if let binding. Just drop the force unwrap like the error message tells you.

if let playerDic = defaults.objectForKey("Player") as? [String: Int] {
    lbLevel.setText(String(playerDic["level"]))
}

Update Sorry just saw your update. So playerDic isn't an optional, but the values returned for keys are optionals. If you ask for the value for a key that is not in the dictionary you will get an optional with the value of nil.

if let 
      playerDic = defaults.objectForKey("Player") as? [String: Int],
      level = playerDic["level"]   {
    lbLevel.setText("\(level)")
}

Here you can bind multiple values in a single if let. Also, you can use String(level) or use string interpolation "(level)" depending on what you prefer.

Tags:

Xcode

Swift