Calling multiple arguments from objective-c to applescript-objc

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.

Answers


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_ 

Need Your Help

Keep plotting window open in Matplotlib

python matplotlib

When writing scripts that use matplotlib, I temporally get an interactive graphing window when I run the script, which immediately goes away before I can view the plot. If I execute the same code

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.