Date
1 - 4 of 4
Translate Services Menu to Swift
Gerriet M. Denkmann
This works:
- (void)lookUppString:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString * _Nullable *)error { NSLog(@“%s",__FUNCTION__); } But this does not: func lookUppString(_ pboard: NSPasteboard, _ userData: String, _ error: AutoreleasingUnsafeMutablePointer<NSString?>) { print(#function) } It prints: Cannot find service provider for selector lookUppString:userData:error: or lookUppString:: for service lookUppString What am I doing wrong? Gerriet |
|
Gerriet M. Denkmann
On 15 Jul 2018, at 14:05, Gerriet M. Denkmann <g@...> wrote:Now this is ok: @objc func nnn(_ pboard: NSPasteboard, _ userData: String) Where nnn = value of “Instance Method name” from Info.plist I am sure this is very well documented somewhere. The problem is that I am too stupid to find this. Gerriet. |
|
Quincey Morris
On Jul 15, 2018, at 03:47 , Gerriet M. Denkmann <g@...> wrote:
This doesn’t look right, and I don’t know why it works. If you put the name “nnn” in the info.plist, the selector it looks up should be “nnn:userData:error:”. The Swift 4 function signature that translates into this selector would be: @objc func nnn(_ pboard: NSPasteboard, userData: String, error: NSErrorPointer) It’s possible that the service lookup tries a number of variant selectors (like KVC does for accessors), for backwards compatibility with older naming conventions, and you were lucky enough to hit on one that works. If you’re interested, it might be worth trying that last function signature to see if that works too. |
|
Gerriet M. Denkmann
On 15 Jul 2018, at 23:23, Quincey Morris <quinceymorris@...> wrote:I did. The error message is: Cannot find service provider for selector nnn:userData:error: or nnn:: for service nnn Which suggest that two selectors are indeed tried. That is: Objective-C uses the traditional form “nnn:userData:error:”, i.e.: - (void)nnn:(NSPasteboard *)pboard userData:(NSString *) userData error:(NSString * _Nullable *)error Whereas Swift now has only two arguments: “nnn::” @objc func nnn(_ pboard: NSPasteboard, _ userData: String) The error parameter has never worked; so it makes sense that Swift finally got rid of it. There are some blogs which recommend a Swift form with error parameter (and only one underline) - same as your suggestion. Obviously some previous incarnation of Swift still did use it. Gerriet. |
|