NSDictionary EXC_BAD_ACCESS

vqd*_*ave 4 exc-bad-access objective-c ios

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
Run Code Online (Sandbox Code Playgroud)

我尝试在Instruments中使用Zombies模板,但我从未得到过对话框.在破坏点时,应用程序在initWithObjectsAndKeys上崩溃.我的死变量在哪里?

Apu*_*urv 16

您不能将原始类型放入Dictionary.用变量total换行NSNumber,然后将其放入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];
Run Code Online (Sandbox Code Playgroud)