简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM