Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDictionary EXC_BAD_ACCESS

NSInteger total = 4556; // Initialize total

// NSLog all fields to make sure the variables are in place
NSLog(@"%@", originField.text);
NSLog(@"%@", destinationField.text);
NSLog(@"%i", [startField.text integerValue]);
NSLog(@"%i", [endField.text integerValue]);
NSLog(@"%i", total);

// Create a dictionary of them
NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Sat. Jan 6th, 2014", @"date", originField.text, @"origin", destinationField.text, @"destination", [startField.text integerValue], @"start", [endField.text integerValue], @"end", total, @"total", @"Personal", @"type", nil];
// EXC_BAD_ACCESS CODE 1

I've tried using the Zombies template in Instruments, but I never get a dialog. When breakpointing, the app crashes on the initWithObjectsAndKeys. Where are my dead variable(s)?

like image 919
vqdave Avatar asked Dec 05 '22 08:12

vqdave


1 Answers

You can not put primitive types into Dictionary. Wrap the variable total with NSNumber and then put it into Dictionary.

NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Sat. Jan 6th, 2014", @"date", 
originField.text, @"origin", 
destinationField.text, @"destination", 
@([startField.text integerValue]), @"start", 
@([endField.text integerValue]), @"end", 
@(total), @"total", 
@"Personal", @"type", nil];
like image 60
Apurv Avatar answered Dec 30 '22 16:12

Apurv