Swift3 optionals chaining in IF conditions bug?

后端 未结 4 676
感动是毒
感动是毒 2020-12-01 20:01

This code worked just fine in Swift 2.3 and I don\'t understand why I have to unwrap TestClass to check if number is bigger than 4. This is whole point of chain

4条回答
  •  时光取名叫无心
    2020-12-01 20:57

    This could also happen on Guard statement. Example:

    var playerLevels = ["Harry": 25, "Steve": 28, "Bob": 0]
    

    for (playerName, playerLevel) in playerLevels {

    guard playerLevels > 0 else {//ERROR !!
        print("Player \(playerName) you need to do the tutorial again !")
        continue
    }
    
    print("Player \(playerName) is at Level \(playerLevels)")
    

    }

提交回复
热议问题