2011-06-15 13 views
5

Estoy tratando de agregar objetos que están en una matriz a un NSDictionary según su posición dentro del NSArray, pero la aplicación falla tan pronto como se asigna el NSDictionary. ¿Alguna idea de por qué?EXC_BAD_ACCESS con NSDictionary

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]]; 

veo todos los valores correctos cuando NSLog los objetos, pero el NSDictionary hace que la aplicación de choque con un error EXC_BAD_ACCESS. Tengo NSZombies habilitado, pero no se muestra nada cuando se bloquea como se mostraría regularmente. ¿Alguna idea sobre lo que está pasando aquí? ¡Gracias por adelantado!

+0

favor pegar el texto del informe de bloqueo y mensajes de error anteriores a su pregunta. –

Respuesta

12
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]]; 

se le olvidó la @ en "lng". Auge.

+0

Wow. Tan estupido. No puedo creer que no haya notado eso. ¡Gracias! –

+0

Esto también funciona ;-) NSDictionary * venue_details_dict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: venue_title, venue_address, venue_lat, venue_lng, nil] forKeys: [NSArray arrayWithObjects: @ "name", @ "address", @ "lat ", @" lng ", nil]]; –

+1

Archivar un error: el compilador debería poder detectarlo. – bbum

2

Para mayor claridad, que comete errores como éste más fácil ver a tratar:

NSDictionary *venue_details_dict = [NSDictionary dictionaryWithObjectsAndKeys: 
    venue_title, @"name", 
    venue_address, @"address", 
    venue_lat,  @"lat", 
    venue_lng,  @"lng", 
    nil];