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

  • SEARCH
  • Home
  • 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 8364053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:20:24+00:00 2026-06-09T12:20:24+00:00

I am very new to objective-C and came across the NSDictionary method allKeysForObject: .

  • 0

I am very new to objective-C and came across the NSDictionary method allKeysForObject:. Seems very useful. However, I have a NSDictionary which has several NSArrays (all of length 2) and which are keyed by NSStrings. Basically, the keys are items and the arrays define their two properties. If I wanted to pull all the item names that have a certain property, could this be done with something like allKeysForObject, or should I just loop over the dictionary and grow a mutable array (seems inefficient).

I’d include a code snippet, but I feel like this question is conceptual enough that code wouldn’t really clarify anything. Oh, what the hell. Here’s some simplified code:

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],nil],@"Car",[NSArray arrayWithObjects:[NSNumber numberWithInt:2],[NSNumber numberWithInt:3],nil],@"Boat",nil];
NSLog(@"%@",[dict allKeysForObject:???]); // this is the line I am not at all sure about.

EDIT: Thank you for the responses so far. I was not clear about my question, though. I am looking for a way to do something more general. I don’t want to retrieve all keys for a particular object, say [1,2], but I want to look in the dictionary for all arrays including the NSNumber 1 and return those keys. So if I added @"Plane",[NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:3],nil], I’d like to somehow query for the NSNumber 1 and get @"Car" and @"Plane". I am getting the sense that this is not what this method was designed to do.

  • 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-06-09T12:20:25+00:00Added an answer on June 9, 2026 at 12:20 pm

    You are looking for -keysOfEntriesPassingTest:…

    NSArray * selectedKeys = [dict keysOfEntriesPassingTest:^(id key, id obj, BOOL *stop)
                              {
                                  return [obj containsObject:[NSNumber numberWithInt:2]];
                              }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Objective-C, and am having some beginner issues. I have an
I'm very new to Objective-C and Cocoa but I've made a simple app which
I'm very much new to objective C. I have a case where I need
I am very new to xcode & Objective-C (having come from PHP) i have
I am very new to XCode and objective-c. This question may have been answered
My method + (void) initialized is not called and I'm very new in Objective
I am very new to Objective-C. Here is what I want. I have a
I'm very new to Objective-C, and am having some beginner issues. I have an
I'm very new to Objective-C. I'm trying to write a method where I create
Hello all! I am very new to xcode and objective-c but I have been

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.