Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.

2015-05-06

Returning error information for a system service call

When a system service is implemented, the function signature that we need to implement in Objective-C is:

- (void)myService:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error;

In Swift, this turns out as:

func myService(pboard: NSPasteboard, userData: String, error: AutoreleasingUnsafeMutablePointer<NSString?>)

The pasteboard and userData parameters will not cause any problems, but the error information that we might want to return can take some puzzling when we encounter this for the first time.
We need to return the error information as a pointer to an NSString object.

In Objective-C this is implemented as follows:

*error = @"Failure, application did not start properly";

In Swift the syntax is:

error.memory = "Failure, application did not start properly"


Happy coding...

Did this help?, then please help out a small independent.
If you decide that you want to make a small donation, you can do so by clicking this
link: a cup of coffee ($2) or use the popup on the right hand side for different amounts.
Payments will be processed by PayPal, receiver will be sales at balancingrock dot nl
Bitcoins will be gladly accepted at: 1GacSREBxPy1yskLMc9de2nofNv2SNdwqH

We don't get the world we wish for... we get the world we pay for.

No comments:

Post a Comment