Re: Translate Services Menu to Swift


Gerriet M. Denkmann
 

On 15 Jul 2018, at 23:23, Quincey Morris <quinceymorris@...> wrote:

On Jul 15, 2018, at 03:47 , 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
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.
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.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.