views:

274

answers:

2

Hi All,

i want to ask question that how can we search in a plist which is of array type and has elements of array type as well. i am searching from a plist which is of string element type and its working fine, but i am not able to search when it has array elements in the plist.

Regards!

A: 

You question is not very clear but if you're looking for a way to locate an object in a NSArray containing NSArrays containing objects (NSStrings), here's an example:

NSArray * l20 = [NSArray arrayWithObjects:@"One", @"Two", nil];
NSArray * l21 = [NSArray arrayWithObjects:@"Three", @"Four", nil];

NSArray * ll = [NSArray arrayWithObjects:l20, l21, nil];

for(id l1obj in ll)
    for(id l2obj in l1obj)
        if([l2obj isEqualToString:@"Three"])
            NSLog(@"Found object three");
diciu
+1  A: 
- (BOOL)searchArray:(NSArray *)array forObject:(id)object {
    if ([array containsObject:object]) {
        return TRUE;
    }

    for (id elem in array) {
        if ([elem isKindOfClass:[NSArray class]]) {
            if ([self searchArray:elem forObject:object]) {
                return TRUE;
            }
        }
    }
    return FALSE;
}

Will handle a two-dimensional array as well as any other depth.

dbarker