println dictionary has “Optional”

后端 未结 2 534
离开以前
离开以前 2020-12-02 02:47

Consider this snippet:

let interestingNumbers = [
    \"Prime\": [2, 3, 5, 7, 11, 13],
    \"Fibonacci\": [1, 1, 2, 3, 5, 8],
    \"Square\": [1, 4, 9, 16, 2         


        
2条回答
  •  忘掉有多难
    2020-12-02 03:28

    In Swift, dictionaries return optionals because if you try to access a key that does not exist, it can return nil

提交回复
热议问题