I am just writing some simple dictionary code as
var picCard: Dictionary<String, Int> = ["jack": 11, "Queen": 12, "King": 13]
But when I access one of the entries in the dict in the playground like
picCard["Jack"]
The output gives me:
{some 11}
Been through the swift programming guide and cant find out why it says 'some'
Those are optionals. Optional is basically defined like this:
enum Optional<T> {
case None
case Some(T)
// ...
}
An optional with a value is Some <value>
, nil
is None
:
var foo: String = "blah" // "blah"
var bar: String? = "bleh" // {Some "bleh"}
In your case, subscripting a Dictionary
returns an optional value, because the key might not exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With