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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:12:04+00:00 2026-05-16T12:12:04+00:00

So I am trying to save arrays into an NSDictionary on the fly. Let

  • 0

So I am trying to save arrays into an NSDictionary on the fly. Let me show you the code and explain what is going on.

for (int x= 0; x <[appDelegate.people count]; x++) {
    Person *aPerson = [[Person alloc] init];
    aPerson = [appDelegate.people objectAtIndex:x];
    if ([appDelegate.groupedBusiness objectForKey:aPerson.business_name] == nil) {
        NSMutableArray *newBusiness = [[NSMutableArray alloc] init];
        //if the business does not exist in the dict, add the person to the business and add it to dict.

                    [newBusiness addObject:aPerson];

        [appDelegate.groupedBusiness setObject:newBusiness forKey:aPerson.business_name];

        [newBusiness release];
        newBusiness = nil;
        //NSLog(@"%@", appDelegate.groupedBusiness);
    } else {
        NSMutableArray *existingBusiness= [appDelegate.groupedBusiness objectForKey:aPerson.business_name];
        [existingBusiness addObject:aPerson];
                  //THIS IS THE LINE I AM NOT SURE ABOUT!!!
        [appDelegate.groupedBusiness setObject:existingBusiness forKey:aPerson.business_name];

        [existingBusiness release];
        existingBusiness = nil;
        //NSLog(@"%@", appDelegate.groupedBusiness);
    }

}

Alright, so the appDelegate has an array of “People” that has a whole bunch of attributes about a person. I am trying to set up a dictionary to sort them by their business names. I am doing this by creating an array and saving it in the dictionary with the business_name as the key. Each iteration of the loop I check to see if the key exists, if it does, pull out the existing array, add the person you are checking, and resave it to the dictionary. However, this does not appear to be happening. Is there some exotic behavior in the NSDictionary class that would prevent that? I have poured over the class web page and can’t find anything. Sorry if this is a noobie question, I am still trying to understand the objective-c classes. Thanks!

  • 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-16T12:12:05+00:00Added an answer on May 16, 2026 at 12:12 pm

    Why do you release existingBusiness? You are not creating an object, just taking the pointer from an array. When you invoke release, retainCount became 0 and object deallocs.

    Just remove the following two lines:

    [existingBusiness release];
    existingBusiness = nil;
    

    and everything should work fine.

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

Sidebar

Related Questions

I am trying to save an int array into the shared preferences. int myInts[]={1,2,3,4};
I have a JSON return that I'm trying to save into a NSDictionary, However,
I'm trying to save some data into an array but unfortunately all the data
I am trying to save multiple image using this code. But instead its saving
I am trying to save an array of records into a mysql database but
I am trying to save JSON data into a MySQL DB & PHP. I've
I'm trying to save a struct with a char* string into a file. struct
I'm trying to convert Morse code into text. I have two text files to
I have a integer named marbles, and am trying to save it into an
I am trying to convert the dataset item into the string and save into

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.