2
votes

I am looking to check if NSMutableArray contains NSMutableDictionary, I know we can check for NSDictionary with

  [array indexOfObjectIdenticalTo:dict];

But cannot work out how to check for NSMutableDictionary. Any hint would be great.

Thanks.

3

3 Answers

2
votes

This should work: [array containsObject: dict];

EDIT:

To get the Index you can use:

NSUInteger index = [array indexOfObject: dict];
1
votes

You can check the objects in array with type of class.

    for (id object in mutableArray) {
    if ([object isKindOfClass:[NSMutableDictionary class]]) {
        // Mutable dictionary object
        NSInteger iIndex = [mutableArray indexOfObject:object];
    }
    else if ([object isKindOfClass:[NSDictionary class]]) {
        // Non-mutable dictionary object
        NSInteger iIndex = [mutableArray indexOfObject:object];
    }
    }
0
votes

isKindOfClass can also be useful here. you can check a specific index this way

if ([[myArray objectAtIndex:myIndex] isKindOfClass:[NSDictionary class]])

whereas this NSDictionary can be replaced by any Data Type that you want to compare with for example NSArray, NSString and others. I hope it helps you in distinguishing the types of data.