Ok, i kind of asked the wrong question so I’ve edited the original question.
I’m storing Arrays within Arrays, as well as NSDictionaries. It’s a utility kind of application and there is no set structure, the user can enter nested information as much as they require.
Ideally I need a method to scroll through the entire contents of my array given a set parameter (a type of class, maybe a dictionary key). Here’s an example..
NSMutableArray *array = [[NSMutableArray alloc]init];
NSMutableDictionary *enteredItem = [[NSMutableDictionary alloc]init];
[enteredItem setObject:@"i'm a title" forKey:@"title"];
[enteredItem setObject:@"i'm an id" forKey:@"id"];
[enteredItem setObject:@"i'm a description" forKey:@"description"];
[enteredItem setObject:@"i'm a timestamp" forKey:@"timestamp"];
[enteredItem setObject:array forKey:@"items"];
[array addObject:enteredItem];
[array addObject:anotherDictionary];
[array addObject:moreDictionaries];
So in the example above, I would need to find the dictionary (and return it) that contains @”i’m an id”.
Hopefully my question is clear. Thanks for any help you can offer.
Recursive approach is correct, but I’m not sure the code samples were very helpful if you don’t already know recursion. Here’s a working solution:
Add these methods:
Then to find your object, just say:
To modify the methods to find a specific object and return the dictionary key, do this instead:
Then to find your key, just say: