When I try to observe a key path that includes an optional (“controller” in 
this case) in Swift, I get a compiler error saying ‘Type of expression is 
ambiguous without more context’ on the backslash in this statement:

        submodelObservation = observe(\.controller.submodel) { object, change in
    // code
        }


    @objc dynamic internal var controller: Controller?

in the the “Controller" class:

    @objc dynamic internal var submodel: SubmodelForImporting?


I’m not clear why this would be, but I admit I missed the discussion the first 
time it happened. If I make “Controller” non-optional the code compiles fine.

Certainly with traditional KVO you can observe key paths that have ‘nil’ values 
in them! Is this something stupid I’m doing, a compiler bug, or a design 
decision? I’m asking here because if it’s a design decision I’d like to appeal 
it, certainly.

-Wil
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to