2

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?

Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165
Mike97
  • 596
  • 5
  • 20
  • possible duplicate of [Method Syntax in Objective C](http://stackoverflow.com/questions/683211/method-syntax-in-objective-c) – Caleb Mar 12 '14 at 20:34

1 Answers1

7

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.

Johannes Fahrenkrug
  • 42,912
  • 19
  • 126
  • 165