Mike97
Mike97

Reputation: 603

Declare an Objective-C method with multiple arguments

I would like to pass NSTask (NSTask, launchpath, and the args) to a function, but sure I need some help with the semantic:

AppleDelegate.h file:

- (void)doTask:(NSTask*)theTask :(NSArray*)arguments :(NSString*)launchPath;

AppleDelegate.m file:

- (void)doTask:(NSTask*)theTask :(NSArray*)arguments :(NSString*)launchPath
{
    self.currentTask = theTask;

    // do currentTask alloc, set the launcpath and the args, pipe and more
}

Here is the code to call "doTask":

NSTask* runMyTask;
NSString *command = @"/usr/bin/hdiutil";
NSArray* taskArgs = [NSArray arrayWithObjects:@"info", @"/", nil];

// Here the error:
[self doTask:runMyTask, taskArgs, command];  // ARC Semantic issue no visible interface for AppleDelegate declares the selector 'doTask'..

The selector appears as undeclared, but I thought I did declare it... Is it possible to do something like this, where is the mistake?

Upvotes: 2

Views: 4918

Answers (1)

Johannes Fahrenkrug
Johannes Fahrenkrug

Reputation: 44836

You should first do a tutorial like this one to understand the basics of Objective-C: http://tryobjectivec.codeschool.com/

About your question. Your method was called doTask:::. You could invoke it like this: [self doTask:runMyTask :taskArgs :command];. However, that is bad practice. You want every parameter reflected in your method name. Also, you don't want your method names to start with do or does.

So, rename your method:

- (void)runTask:(NSTask *)theTask arguments:(NSArray *)arguments launchPath:(NSString *)launchPath;

And call it like this:

[self runTask:runMyTask arguments:taskArgs launchPath:command];

Done.

Upvotes: 7

Related Questions