>. Enter" instead of ">. Enter" I am new to Swift and am trying to learn...">

Why type "testScores [" dave "]" is "Optional <Array <Int>>. Enter" instead of "<Array <Int>>. Enter"

I am new to Swift and am trying to learn the concept of index. When I tried to figure out the return value of testScores ["dave"], I expected Array<Int>.Type, however, instead of the IDE instead Optional<Array<Int>>.Type.

Why is this so? Did I miss something?

var testScores = ["dave": [82, 84, 86], "jen": [23, 14, 5], "ben": []]

testScores["dave"].dynamicType
+4
source share
1 answer

Any time you get a value from Dictionary, it will be optional. It may or may not have an entry for the specified key. That is why you need to expand the option before you can use it.

+3

Source: https://habr.com/ru/post/1628414/


All Articles