Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:55:28+00:00 2026-05-28T16:55:28+00:00

Ok, i kind of asked the wrong question so I’ve edited the original question.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:55:28+00:00Added an answer on May 28, 2026 at 4:55 pm

    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:

    - (id)findObjectWithKey:(id)key inArray:(NSArray *)array
    {
        for (id object in array)
        {
            if ([object isKindOfClass:[NSArray class]])
            {
                return [self findObjectWithKey:key inArray:object];
            }
            else if ([object isKindOfClass:[NSDictionary class]])
            {
                return [self findObjectWithKey:key inDictionary:object];
            }
        }
        return nil;
    }
    
    - (id)findObjectWithKey:(id)key inDictionary:(NSDictionary *)dict
    {
        for (id subKey in dict)
        {
            id object = [dict objectForKey:subKey];
            if ([subKey isEqual:key])
            {
                return object;
            }
            else if ([object isKindOfClass:[NSArray class]])
            {
                return [self findObjectWithKey:key inArray:object];
            }
            else if ([object isKindOfClass:[NSDictionary class]])
            {
                return [self findObjectWithKey:key inDictionary:object];
            }
        }
        return nil;
    }
    

    Then to find your object, just say:

    id object = [self findObjectForKey:@"title" inArray:array];
    

    To modify the methods to find a specific object and return the dictionary key, do this instead:

    - (id)findKeyWithObject:(id)key inArray:(NSArray *)array
    {
        for (id object in array)
        {
            if ([object isKindOfClass:[NSArray class]])
            {
                return [self findKeyWithObject:key inArray:object];
            }
            else if ([object isKindOfClass:[NSDictionary class]])
            {
                return [self findKeyWithObject:key inDictionary:object];
            }
        }
        return nil;
    }
    
    - (id)findKeyWithObject:(id)object inDictionary:(NSDictionary *)dict
    {
        for (id key in dict)
        {
            id subObject = [dict objectForKey:key];
            if ([subObject isEqual:object])
            {
                return key;
            }
            else if ([subObject isKindOfClass:[NSArray class]])
            {
                return [self findKeyWithObject:object inArray:object];
            }
            else if ([subObject isKindOfClass:[NSDictionary class]])
            {
                return [self findKeyWithObject:object inDictionary:object];
            }
        }
        return nil;
    }
    

    Then to find your key, just say:

    id key = [self findKeyWithObject:object inArray:array];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this kind of question has been asked before, but there is a
i had asked earlier about the same kind of question but that was in
I've kind of asked this question earlier so sorry for asking a bit similar
I've kind of asked this question before - What does JVM flag CMSClassUnloadingEnabled actually
I know this question has been kind of asked and have looked into the
I know similar kind of question has been asked many times but seriously i
I know this kind of question gets asked alot, but I still haven't been
This is kind of a follow-up question to a question I asked over here
I asked this kind of question before, but didn't receive any good answers, perhaps
Doing a search around I've found this kind of question being asked in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.