2014-02-22 26 views
0

我想NSTask(NSTask,launchpath和參數)傳遞給函數,但肯定我需要一些幫助與語義:聲明與多個參數的Objective-C的方法

AppleDelegate.h文件:

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

AppleDelegate.m文件:

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

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

下面是代碼調用 「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'.. 

選擇器顯示爲未聲明,但我認爲我確實聲明瞭它... 是否有可能做這樣的事情,錯誤在哪裏?

+0

[Objective C中的方法語法]的可能的重複(http://stackoverflow.com/questions/683211/method-syntax-in-objective-c) – Caleb

回答

4

你應該首先做一個教程這樣一個理解的Objective-C的基礎知識:http://tryobjectivec.codeschool.com/

關於你的問題。你的方法被稱爲doTask:::。你可以像這樣調用它:[self doTask:runMyTask :taskArgs :command];。但是,這是不好的做法。您希望每個參數都反映在方法名稱中。此外,您不希望方法名稱以dodoes開頭。

所以,重命名你的方法:

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

,並調用它是這樣的:

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

完成。

+0

謝謝,它工作:-) – Mike97