[swift-evolution] SE-0064 Property Selectors and KVO

Rob Napier robnapier at gmail.com
Sat Jun 4 09:18:07 CDT 2016


Currently KVO requires hard-coding strings to check the keypath. Does
SE-0064 cover returning a string when a string is required? For example:

override func observeValueForKeyPath(keyPath: String?,

                                     ofObject object: AnyObject?,

                                     change: [String : AnyObject]?,

                                     context: UnsafeMutablePointer<Void>) {

    if let changingThing = object as? Thing,

           keyPath = keyPath where changingThing === thing {


        switch keyPath {

        case "thingWatched": ...


I'd like to replace that last line with:

        case #selector(Thing.thingWatched):

Or something similarly non-stringy.

Alternately, this comes back to your "Referencing Objective-C key-paths"
proposal, but I'm wondering if 0064 already covers this case.

-Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160604/f8e63234/attachment.html>


More information about the swift-evolution mailing list