Error with methods providing services

Hi All!

I’m trying to implement a few services in my app, and I’d like to use the NSUserData string in the property list to have the services perform differently depending on how they are called.

The problem looks like I can’t find the right syntax to use for the method.

The services work fine if I use the following method, i.e.- deleting the userData and error arguments:


on helloWorld__(pboard)
    display dialog "Hello World"
end helloWorld__

. but of course I don’t get any strings from the userData argument.

If I try to implement the userData:error: part of the method, I get an error: “Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)” and the app freezes in Xcode.

I’ve tried to change the syntax, but it still fails the same way every time:


on helloWorld_userData_error_(pboard, userData, anError)
    display dialog "Hello World"
end helloWorld_userData_error_


 on helloWorld:pbData userData:uData |error|:aErr
     display dialog "Hello World"
 end helloWorld:userData:|error|:

I’ve included the part of the documentation that deals with the method below.

Thanks for taking a look and please let me know if there’s anything you think I should try.

Thanks so much!!!

The documentation states:

Listing 2 Service method


- (void)simpleEncrypt:(NSPasteboard *)pboard
    userData:(NSString *)userData error:(NSString **)error {
 
     // Test for strings on the pasteboard.
     NSArray *classes = [NSArray arrayWithObject:[NSString class]];
     NSDictionary *options = [NSDictionary dictionary];
 
     if (![pboard canReadObjectForClasses:classes options:options]) {
          *error = NSLocalizedString(@"Error: couldn't encrypt text.",
               @"pboard couldn't give string.");
          return;
     }
 
     // Get and encrypt the string.
     NSString *pboardString = [pboard stringForType:NSPasteboardTypeString];
     NSString *newString = [self rotateLettersInString:pboardString];
     if (!newString) {
          *error = NSLocalizedString(@"Error: couldn't encrypt text.",
               @"self couldn't rotate letters.");
          return;
     }
 
     // Write the encrypted string onto the pasteboard.
     [pboard clearContents];
     [pboard writeObjects:[NSArray arrayWithObject:newString]];
}