在我的實例方法,想一個BOOL參數比較靜態變量的內容,例如:比較兩個布爾值
- (NSArray*)myMethod:(NSString*)someString actualValuesOnly:(BOOL)actualValuesOnly {
static NSString *prevSsomeString;
static BOOL prevActualValuesOnly;
static NSArray *prevResults
if ([someString isEqualToString:prevSomeString] &&
([actualValuesOnly isEqual: prevActualValuesOnly])
// HOW TO COMPARE THESE TWO BOOLEANS CORRECTLY??
{ return prevResults; }// parameters have not changed, return previous results
else { } // do calculations and store parameters and results for future comparisons)
什麼是做到這一點的正確方法是什麼?
嗨馬提亞斯,謝謝你的回答。我認爲'BOOL's存儲爲'NSNumber'對象。不會'=='只是比較它們的指針而不是它們的實際值? – AlexR
BOOL是一個基本類型,例如int或float。直接比較它。 http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html –