I was implementing a MacOS Services plugin and stumbled onto a Swift/ObjC interaction I am not able to solve. In ObjC, the signature for calling Service method looks like this:
- (void) translateService:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
I am able to get a Swift equivalent built and working, but I don't know what to do about (NSString **) error. I have tried AutoreleasingUnsafeMutablePointer<NSString?>?
, but I get a complaint from the compiler: "Cannot assign to value: 'error' is a 'let' constant" when I tried to assign an NSString to the error parameter. Here is what I have (which I am sure is not right)
@objc func translateService( _ pboard: NSPasteboard, userData: String, error: AutoreleasingUnsafeMutablePointer <NSString?>?) {
if let types = pboard.types {
if !types.contains(NSPasteboard.PasteboardType.string) {
//TODO: Error
error = NSString("Does not contain String data")
return
}
How do you mimic this functionality in Swift? How do you return an error string in that parameter?