NSMutableArray中包含的对象多串

问题描述 投票:0回答:2

我得到了结果数组的是这样的

shape= { 1,2,3,4,5,6,7}
if([shapes containsObject:@"10"])
{
        ...
}
else if([shapes containsObject:@"1"])
{
       ...
}

如果我要选择多个对象包含在我的数组值就像我第二次拿到阵列像5,6,7我想用5,6,7所有的值该怎么做?

ios objective-c ios8
2个回答
0
投票

尝试这个

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"])
  {
   }
 }

0
投票

你可以尝试这样的,如果你想比较多个值: -

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];文字的情况下,

© www.soinside.com 2019 - 2024. All rights reserved.