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 981939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:37:17+00:00 2026-05-16T04:37:17+00:00

This is a bit complex. I’ve created an array (NSArray) called pointsOfInterest. The elements

  • 0

This is a bit complex.

I’ve created an array (NSArray) called pointsOfInterest.

The elements of this array are NSDictionary objects. Each dictionary has two keys, “headerTitle” and “rowObjects.” The value for “headerTitle” is a simple NSString; the object for “rowObjects” is another NSArray of objects; each of these is a custom class.

See the code below.

for (NSDictionary *dict in pointsOfInterest) {
    NSArray *keys = [dict allKeys];
    for (NSString *key in keys) {
        //NSLog(@"Key %@",key);
    }       
    NSString *category = [dict valueForKey:@"headerTitle"];
    [poiCategories addObject:category];
}

So, I’m enumerating through the array, getting individual dictionary objects into dict. I then run through all of its keys – if I uncommented the NSLog line, it would display something like this:

2010-08-06 14:00:17.236 TourGuide[4479:207] Key headerTitle
2010-08-06 14:00:17.237 TourGuide[4479:207] Key rowObjects
2010-08-06 14:00:17.238 TourGuide[4479:207] Key headerTitle
2010-08-06 14:00:17.239 TourGuide[4479:207] Key rowObjects

It then constructs a new, flat array, containing the values from all of the “headerTitle” keys.

First, I’m well aware that I should be able to do this:

poiCategories = [[pointsOfInterest valueForKey:@"headerTitle"] retain]

And get the values for the various “headerTitle” keys. Doing that, however, crashes the app. What’s weird, is that the above for construct works fine… IF I leave in the internal for loop. If I remove that for loop, and its useless NSLog, leaving just this:

for (NSDictionary *dict in pointsOfInterest) {
    NSString *category = [dict valueForKey:@"headerTitle"];
    [poiCategories addObject:category];
}

Then it crashes. It does not grace me with any kind of trappable error that I can find.

Any reason anyone can think of?

  • 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-16T04:37:17+00:00Added an answer on May 16, 2026 at 4:37 am

    edit Louis pointed out in one of the comments that -[NSDictionary valueForKey:] will forward on to objectForKey: unless the key begins with @. Source However, I’d still change it to use objectForKey: just for semantic clarity.

    Use objectForKey: instead of valueForKey:. They have very different semantics and implementations. valueForKey:@"headerTitle" will look for an NSDictionary method called headerTitle and return the result of that method (or if it doesn’t exist, will likely crash), whereas objectForKey: actually goes and looks stuff up in the dictionary’s hash table structure to find the object you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so this is a bit complex but I need to loop through this
This case is a bit complex, I hope I will simplify it well. My
Sorry if this question seems a bit complex but I think its all related
This is a bit complex and I really don't now if it is possible.
This is a bit complex so I hope I word this right. I have
I've created a bit complex theme, which includes a slider. However, the slider needs
This question is simple, but the set-up's a bit complex. Please bear with me...
This is a bit complex - so here we go. I am developing a
this is the last part of my a bit more complex homework which I
This bit of code is taking almost a half second to execute. Could somebody

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.