> On Nov 14, 2016, at 11:07 AM, Jordan Rose via swift-evolution 
> <[email protected]> wrote:
> 
> This doesn’t seem unreasonable, but I’m not sure if that makes it reasonable. 
> :-) What’s your use case? The stripped-down code seems like it could use any 
> unique key, including #function.
> 
> Jordan


One use case for bare `#selector` would be in patterns like 
NSTextViewDelegate’s -textView:doCommandBySelector:, where there are many call 
sites that need to pass the selector (and thus are open to copy-paste errors). 
I could imagine having a helper to make this less error prone and less verbose:

class SomeView : NSView {
        private func validate(selector: Selector = #selector, action: (Void) -> 
Void) -> Bool {
                guard checkDelegate(selector) else {
                        return
                }
                action()
        }

        @objc func action1(_ sender: AnyObject?) {
                validate {
                    // do action
                }
        }

        ...

        @objc func actionN(_ sender: AnyObject?) {
                validate {
                    // do action
                }
        }

}

-tim

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

Reply via email to