我得到了结果数组的是这样的
shape= { 1,2,3,4,5,6,7}
if([shapes containsObject:@"10"])
{
...
}
else if([shapes containsObject:@"1"])
{
...
}
如果我要选择多个对象包含在我的数组值就像我第二次拿到阵列像5,6,7我想用5,6,7所有的值该怎么做?
尝试这个
shape = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7",nil];
if ([shape containsObject: @"10"]) // YES
{
// Do something
}
另一种选择
for (NSString* str in shape)
{
if ([str isEqualToString:@"10"])
{
}
else if ([str isEqualToString:@"1"])
{
}
}
你可以尝试这样的,如果你想比较多个值: -
NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];
if([shapes containsObject:@10] || [shapes containsObject:@5] || [shapes containsObject:@7])
{
NSLog(@"found");
}
else
{
NSLog(@"Not found");
}
注: - 您的阵列格式应该是这样的,在Objective-C的NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];
文字的情况下,