2011-06-23 89 views
2

我哈瓦含有以下內容NSArray containsObject NSString不工作?

<CFArray 0x910e1a0 [0x2952380]>{type = mutable-small, count = 8, values = (
    0 : <CFString 0x910e0d0 [0x2952380]>{contents = "NR-Adult"} 
    1 : <CFString 0x910e0f0 [0x2952380]>{contents = "NC-17/TV-MA"} 
    2 : <CFString 0x910e110 [0x2952380]>{contents = "R"} 
    3 : <CFString 0x910e120 [0x2952380]>{contents = "PG-13/TV-14"} 
    4 : <CFString 0x910e140 [0x2952380]>{contents = "PG/TV-PG"} 
    5 : <CFString 0x910e160 [0x2952380]>{contents = "G/TV-G"} 
    6 : <CFString 0x910e170 [0x2952380]>{contents = "TV-Y/TV-Y7"} 
    7 : <CFString 0x910e190 [0x2952380]>{contents = "NR"} 

我們比較針對PG-13

[RatingsList containsObject:@"PG-13"] 

返回虛假的數組列表(RatingsList)。

回答

12

當然,它返回false。您的陣列不包含「PG-13」,儘管它包含「PG-13/TV-14」。

9

使用簡單的NSPredicate。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains %@", aString]; 
NSArray *filteredArray = [RatingsList filteredArrayUsingPredicate:predicate]; 
if ([filteredArray count] > 0) return YES; 
return NO;