3

I have a applescript-objc script with a method as follows :-

on say_(phrase, userName)
    set whatToSay to "\"" & phrase & " " & userName & "\""
    say whatToSay
end say_

And i want to call this method from objective-c but cant seem to figure out how to call methods with multiple arguments, i have no problem calling methods with only one argument as follows :-

@interface NSObject (ASHandlers)
- (void)say:(NSString *)phrase;
@end

@implementation AppDelegate

@synthesize window, sayTextField;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
   scriptFile = NSClassFromString(@"Test");
   if ( !scriptFile ){
      // Handle errors here
   return;
   }
}

- (IBAction)say:(id)sender{
   NSString *phrase = [sayTextField stringValue];
   [scriptFile say:phrase];
}

please can someone help.

Regards, Andy.

1 Answer 1

2

For starters, IBActions must have a signature of:

-(void)action;
-(void)actionWithSender:(id)sender;
-(void)actionWithSender:(id)sender event:(UIEvent*)event;

So you can't have an IBAction with multiple arguments if that's what you were looking for.

However, to answer your question, to have a method with multiple arguments, in Objective-C, it would look like this:

- say:(NSString *)textToSay withUserName:(NSString *)userName {
   ...
}

In AppleScriptObjC, you move all of your Objective-C method parameters to the beginning of the method name, replace the colons with underscores, and put your arguments in the parentheses.

on say_withUserName_(textToSay, userName)
    ...
end say_withUserName_ 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.