數組我有這樣的代碼:警告時,我充滿BOOL
BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:booleanValue];
此代碼給了我,說一個警告:
incompatible integer to pointer conversion: sending BOOL to parameter of type 'id'
爲什麼?
數組我有這樣的代碼:警告時,我充滿BOOL
BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:booleanValue];
此代碼給了我,說一個警告:
incompatible integer to pointer conversion: sending BOOL to parameter of type 'id'
爲什麼?
你需要打你BOOL
與NSNUmber
這樣的:
BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:[NSNumber numberWithBool:booleanValue]];
然後,檢索您的BOOL
值,你拆箱它使用boolValue
:
BOOL b = [[arrayZone objectAtIndex:index] boolValue];
這問題似乎是重複的Objective C Boolean Array
實質上,BOOL是一種基本類型 - 您必須將其包裝在一個Object中才能擺脫警告。
BOOL是一種原始類型,您的數組需要一個對象。這就是爲什麼你需要把它包裝在NSNumber中。但是對於更新的xcode,您只需鍵入@YES或@NO,xcode將它視爲numberWithBool。 因此,而不是:
BOOL booleanValue = TRUE;
[arrayZone replaceObjectAtIndex:indexZone withObject:[NSNumber numberWithBool:booleanValue]];
現在可以使用
[arrayZone replaceObjectAtIndex:indexZone withObject:@YES];
aaaaaah好的.....謝謝 – CrazyDev 2011-04-26 14:51:16