简体   繁体   中英

NSMutableArray Contains Object multiple strings

I got result's of array Like this

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

if I want to selected multiple Contain's object in which I got array value's like second time I got array like 5,6,7 I want to use all values of 5,6,7 how to do that?

try this

shape = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7",nil];

if ([shape containsObject: @"10"]) // YES
 {
// Do something
 }

another choice

for (NSString* str in shape) 
{
if ([str isEqualToString:@"10"])
  {
   }

 else if ([str isEqualToString:@"1"])
  {
   }
 }

You can try like this, if you want to compare multiple values:-

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");
}

Note:- Your array format should be like this in case of literals in objective-c NSArray *shapes= @[@1,@2,@3,@4,@5,@6,@7];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM