why does intellisense insert a ? in this asignment

I have the following code

   let moveDirections = ["East": CGPoint(x: 1.0, y: 0.0),
               "North": CGPoint(x: 0.0, y: 1.0),
               "South": CGPoint(x: 0.0, y: -1.0),
               "West": CGPoint(x: -1.0, y: 0.0),
           ]

        let direction = "South"
        let cdx = moveDirections[direction]?.x 

Why does it insert the ? Surely the moveDirections variable contents is not optional.

That's the case with any dictionary:

aDictionary["some key"] always returns an optional.

If key has a value, you get it, otherwise you get nil.

I have worked round this using the following code

    let moveDirections: [(Double,Double)] = [(1.0, 0.0), // East                           (0.0, 1.0),   // North                           (1.0, 1.0),   // NorthEast                           (-1.0, 0.0),  // NorthWest                           (0.0, -1.0),  // South                           (1.0, -1.0),  // SouthEast                           (-1.0, -1.0), // SouthWest                           (-1.0, 0.0)   // West                         ]     var directions = ["East","North","NorthEast","NorthWest","South","SouthEast","SouthWest","West"]         let id = directions.firstIndex(of: direction)         let dt = moveDirections[id!]         let dx = dt.0         let dy = dt.1

What is direction here ? I suppose let direction = "South"

          let id = directions.firstIndex(of: direction)

So you force unwrap.

but test with

let direction = "south"

app crashes here, as expected.

          let dt = moveDirections[id!]

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

So, that did not solve it.

why does intellisense insert a ? in this asignment
 
 
Q