2

I have on NSMutableArray like this:

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0",@"0", nil];

now I want check if all object in my array are to same and equal to 0 doing certain work!!!. but I don't know about this. please guide me.

2 Answers 2

5

My friend try this:

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0",@"0", nil];
NSCountedSet *filter = [NSCountedSet setWithArray:array];

//this condition check number of 0 value with your array count
//if number of 0 equal to array count this means that all object in array is 0
if ([filter countForObject:@"0"] == [array count]) {
   NSLog(@"all objects are 0");
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the usual for statement:

for (int i = 0; i < [array count]; i++)
{
    NSString *string = [array objectAtIndex:i];
    // Check for >0
}

Or fast enumeration:

for (NSString *string in array)
{
    // Check for >0
}

I didn't fill on purpose the check part, considering that you are a iOS (i guess) beginner can i recommend a good book on iOS programming? iOS Programming: The Big Nerd Ranch Guide

1 Comment

my friend I want check if all object in my array are to same and equal to 0 doing certain work!!!

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.