2010-07-02 57 views
0

確定這裏是導致錯誤的部分代碼:目標C錯誤:傳遞的參數1「setStringValue:」從兼容的指針類型

char charlieReturn[10000]; 
charlieReturn[10000] = system("osascript /applications/jarvis/scripts/getTextCharlieResponce.scpt"); 


self.charlieOutput.stringValue = charlieReturn; 

的getTextCharlieResponce.scpt返回是這樣的:「嗨我的名字叫查理「,也許有時會比這更長。該腳本返回純文本。我需要快速幫助!

在此先感謝! :d

利亞

+1

什麼是charlieOutput和charlieOutput.stringValue? 錯誤告訴你,你正在嘗試將stringValue設置爲一個char數組,並且該stringValue不是一個char數組。 – 2010-07-02 20:04:56

回答

6

不幸的是,你的代碼有很多問題。

  1. C功能system返回腳本的標準輸出爲char*

  2. 即使返回char*功能,則無法將其分配到的char一個數組,你做的事:

    char* str="aeiou"; 
    char foo[100]; 
    foo[100]=str; /* doesn't work */ 
    foo=str; /* doesn't work either */ 
    
  3. 可可的串類,NSString*,不C字符串char*,雖然如果你想有一個串出的

    NSString* str=[NSString stringWithUTF8String:"aeiou"]; 
    

:你可以在兩者之間輕鬆轉換一個蘋果腳本調用,你需要做到以下幾點:

  1. 準備一個NSAppleScript

    NSDictionary* errorDict; 
    NSAppleScript* script=[[NSAppleScript alloc] 
             initWithContentsOfURL:[NSURL fileURLWithPath:@"path/to/script" ] 
                 error:&errorDict]; 
    
  2. 執行並得到答覆:

    NSAppleEventDescriptor* desc=[script executeAndReturnError:&errorDict]; 
    NSString* result=[desc stringValue]; 
    
  3. 發佈腳本:

    [script release]; 
    

學習C & Objective-C玩得開心!

+1

+1好吧,更快,更深入......無需複製。 – Eiko 2010-07-02 20:12:46

0

你試圖分配一個字符數組什麼大概是一個NSString。試試這個:

self.charlieOutput.stringValue = [NSString stringWithUTF8String:charlieReturn]; 
+0

好吧,它使charlieOutput空白... :(任何想法?? – objectiveccoder001 2010-07-02 20:11:18

相關問題