Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXC_BAD_ACCESS with NSDictionary

I'm trying to add objects that are in an array to an NSDictionary based on their position inside of the NSArray, but the app crashes as soon as the NSDictionary is allocated. Any ideas why?

NSString *venue_title = [venues objectAtIndex:[actionSheet tag]];
NSString *venue_address = [venues_full_address objectAtIndex:[actionSheet tag]];
NSString *venue_lat = [venues_lat objectAtIndex:[actionSheet tag]];
NSString *venue_lng = [venues_lng objectAtIndex:[actionSheet tag]];        
NSLog(@"%@, %@, %@, %@", venue_title, venue_address, venue_lat, venue_lng);        
NSDictionary *venue_details_dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:venue_title, venue_address, venue_lat, venue_lng, nil] forKeys:[NSArray arrayWithObjects:@"name", @"address", @"lat", "lng", nil]];

I see all the right values when I NSLog the objects, but the NSDictionary makes the app crash with a EXC_BAD_ACCESS error. I have NSZombies enabled, but nothing is being shown when it crashes like it would regularly show. Any ideas on what's going on here? Thanks in advance!

like image 965
Raphael Caixeta Avatar asked Jun 15 '11 22:06

Raphael Caixeta


1 Answers

NSDictionary *venue_details_dict = [[NSDictionary alloc] initWithObjects:
     [NSArray arrayWithObjects:venue_title, venue_address, venue_lat, venue_lng, nil]
   forKeys:
     [NSArray arrayWithObjects:@"name", @"address", @"lat", "lng", nil]];

You forgot the @ on "lng". Boom.

like image 87
bbum Avatar answered Sep 25 '22 17:09

bbum