1

I want to find multiple values in one NSMutableArray. Like if this two values found then in this array then i want to execute my condition.For Example this is my array

NSMutableArray findValues have 1,2,3,4,5.Now i want to put condition like this

if([findvalues have string @"1"] && [findValues have string @"4"]){

    //execute code

}

can anyone suggest how to do this?

2
  • 1
    use if (yourArray.containsobject(yourObject)) {//Object find}; Commented Mar 30, 2016 at 7:20
  • Why are those numbers in strings? Commented Mar 30, 2016 at 7:28

4 Answers 4

3

You can use following code to find object in Array,

if ([array containsObject:@"1"] && [array containsObject:@"4"]) {
        //execute code
    }
Sign up to request clarification or add additional context in comments.

Comments

2

use containsObject:

if([findvalues containsObject:@"1"] && [findValues containsObject:@"4"]){

    //execute code
}

Comments

2

Use below code:

  if ([findvalues containsObject:@"1"] && [findvalues containsObject:@"4"]) {

    // Do something here...
  }

Comments

0

To filter array by multiple values, use NSPredicate

Create an object class, which contains an object value and compare the text by using given format

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"(value   contains[c] %@) || (value contains[c] %@)", @"f", @"x"];

NSMutableArray* list = [NSMutableArray arrayWithArray:[findValues filteredArrayUsingPredicate:predicate]];

Hope this solution helps you.. Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.