How to correctly define type (variable type) of a dictionary value?

Viewed 30

So I’m very early on in Swift, and was just trying to get the hang of different things, and I was trying to make and print a dictionary value. However this is what I get:

let shoeSize = [
"humanOne": 1.2,
"humanTwo": 2.1
]
var mySize = shoeSize["humanOne"]
print(mySize)

Then I am given this multitude of errors:

compiler.swift:23:7: warning: expression implicitly coerced from 'Double?' to 'Any'
print(mySize)
      ^~~~~~
compiler.swift:23:7: note: provide a default value to avoid this warning
print(mySize)
      ^~~~~~
             ?? <#default value#>
compiler.swift:23:7: note: force-unwrap the value to avoid this warning
print(mySize)
      ^~~~~~
            !
compiler.swift:23:7: note: explicitly cast to 'Any' with 'as Any' to silence this warning
print(mySize)
      ^~~~~~
             as Any

I have gathered that I need to define the types of values within the dictionary but not even sure.

Thanks for the help!

0 Answers
Related