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.
writeFile
in and, if it's not the app delegate, how does the object running that method get its reference to the projects array? – Phillip Mills Aug 4 '12 at 14:17