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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:15:53+00:00 2026-06-09T11:15:53+00:00

I have a method called getProjects . In my method I parse data from

  • 0

I have a method called getProjects. In my method I parse data from json. I save name and id of the project in my instance variable projectsArray which is an NSMutableArray.

The problem is that I have a button (IBAction) called writeFile and if I try to log the array on click, my app crashes. The error message is ESC_BAD_ACCESS. But why? I am using ARC.
`Method getProjects

- (void)getProjects {
int count = 0;
self.projectsArray      = [NSMutableArray arrayWithCapacity:10];
SBJsonParser *parser    = [[SBJsonParser alloc] init];

NSURLRequest *request   = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@projects.json", urlPath]]];
NSData *response        = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString *json_string   = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSArray *projects       = [parser objectWithString:json_string error:nil];

for (NSDictionary *project in projects) {
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2];

    [dict setObject:[project objectForKey:@"name"] forKey:@"name"];
    [dict setObject:[project objectForKey:@"id"] forKey:@"id"];

    [self.projectsArray insertObject:dict atIndex:count];
    [self.selectProject addItemWithTitle:[project objectForKey:@"name"]];
    count++;
}

}

And I call the method in applicationDidFinishLaunching

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    [self getProjects];
    NSLog(@"%@", self.projectsArray);
}

The log in my applicationDidFinishLaunching returns my array.

  • 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-09T11:15:56+00:00Added an answer on June 9, 2026 at 11:15 am

    Well, it seems you have already found the cause of the issue:

    I changed assign to retain and now it works. But why?

    The reason is that by declaring the property as assign, when you set it, its value is not retained.

    So:

    1. you create the array like this:

        self.projectsArray      = [NSMutableArray arrayWithCapacity:10];
      
    2. arraywithCapacity will give you an autoreleased object;

    3. the object is not retain when assigning it to the property;

    4. at some point in time, before the NSLog is executed, the object is deallocated.

    5. crash.

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

Sidebar

Related Questions

I have a controller method called Edit in which the user can edit data
I have a method called GetObjectsRelatedToAType, e.g. GetCarsRelatedToDealership. Which approach is better from a
I have a method called setSound() which is setting up a queue and adding
I have a controller which has a method called history class UsersController < ApplicationController
I have a method called getTheUserInput in a class which returns a String which
I have a method called save_title : def save_title (data) ... [ if the
I have a method called Rotate and I am calling it from another method
I have a method called xyz which returns an object. private XYZ xyz() {
In ObjectDataSource we have a method called SelectMethod and TypeName in which we can
I am currently working on a project in C#. I have a method called

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.