tags:

views:

40

answers:

1

I am trying something very trivial here, but the program is terminating with a “EXC_BAD_ACCESS” in the NSLog. I am attempting to populate a mutable array with several dictionaries like this:

NSMutableArray *_recipientsMutArray = [[NSMutableArray alloc] init];

NSDictionary *r1 = [[NSDictionary alloc] initWithObjectsAndKeys: @"firsValue", @"firstKey", @"secondValue", @"secondKey", nil];

[_recipientsMutArray addObject:r1];

[r1 release];

Why?

+1  A: 

The code that you have provided is fine, and shouldn't cause EXC_BAD_ACCESS, however you mention a crash with NSLog. A common mistake to make with NSLog is to provide a C-style string for the format string, rather than an NSString. The following will cause errors:

int i = 4;
NSLog("%d", i); // oh no!

Instead, you need to ensure that NSLog's first argument is an NSString, like this:

int i = 4;
NSLog(@"%d", i); // yay!
dreamlax
Yup, I've spent a few hours on that one!
maralbjo