2010-02-10 27 views
0

嘗試應用補丁和彙編收到警告消息:這是什麼錯誤消息抱怨?以及如何解決它?

<some_file>: In function '-[XXXXX saveAndCreate:]': 
<some_file>:262: warning: 'NSString' may not respond to '-stringByReplacingOccurrencesOfString:withString:' 
<some_file>:262: warning: (Messages without a matching method signature 
<some_file>:262: warning: will be assumed to return 'id' and accept 
<some_file>:262: warning: '...' as arguments.) 
distcc[6493] ERROR: compile (null) on localhost failed 

這是抱怨這個代碼,

[clientHost findAvailableIn: 
    [clientHost defaultVMPath] 
    baseName: 
     [displayName stringByAppendingPathExtension:PL_BUNDLE_EXTENSION] 
    nameFormat:[[displayName 
        stringByReplacingOccurrencesOfString:@"%" 
               withString:@"%%"] 
        stringByAppendingString:@" %u.xxxx"] 
    startIndex:2 
    contextInfo:contextInfo]; 

,這裏是編譯命令的一部分:

lin32/gcc-5363-1/bin/i686-apple-darwin8-gcc -mmacosx-version-min=10.4 -arch i386 -march=pentium-m -mtune=prescott -Werror -Wall -Wno-trigraphs -Wreturn-type -Wunused-variable -pipe -O2 -g3 -gfull -Wno-pointer-sign -x objective-c -fobjc-exceptions -fpascal-strings -fmessage-length=0 

使用google搜索警告並嘗試了方法here,但仍收到警告消息。

我對Mac的發展一無所知,如果這是明顯的東西(我不知道上面提供的信息是否足夠,讓我知道還有什麼需要提供)。感謝名單。

編輯: 1)擴展代碼塊。 2)更正警告信息。

+0

你能否澄清你的編輯? – FelixLam

+0

我擴展了代碼塊,以便它可能會更清楚您的答案中不變的接收器是什麼。 –

+0

你能否通過創建新變量來更好地分離問題,並嘗試將代碼格式化爲在SO中可讀? – FelixLam

回答

2

該警告引用了您引用的不同行。您使用的訊息被稱爲stringByReplacingOccurrencesOfString:withString:,在NSString上沒有問題。但是,方法replaceOccurrencesOfString:withString試圖更改接收器。 NSString是不可變的,因此不能更改。如果您想使用該方法,請將其發送到NSMutableString對象。

+0

我編輯的代碼,你的意思是nameFormat是不可變的? –

+0

您未在發佈的代碼中使用'replaceOccurrencesOfString:withString'。所以我不能真正幫助。 – FelixLam

+0

真的很抱歉混淆。警告消息是相同的。 –

1

你在導入<Foundation/Foundation.h>?非常令人驚訝的是,您會收到此警告,但在-stringByAppendingPathExtension上沒有任何警告。這真的是你收到的唯一警告嗎?

我建議分解代碼來創建一些臨時變量。你正在做這麼多的嵌套方法調用,這使得很難確定你的錯誤在哪裏。編譯器會優化大多數臨時變量,所以當代碼更清晰時,沒有理由避免它們。

+0

是的,那是我得到的唯一警告信息。我會讓我的同事去做。現在幾乎他們的時間。感謝名單。 –

相關問題