Kazmi
Kazmi

Reputation: 593

EXC_BAD_ACCESS with NSManagedObject

i am trying to insert values in a number of tables (25 to be exact), i am able to insert records in all the table except for one, and that is because of one single Attribute, if i remove that attribute it starts saving the data into the table but when i add that attribute and try to set its value, it terminates with EXC_BAD_ACCESS.

i tried changing the name of the attribute even the table's, but didnt work. below is my code::

Ashes *ashesObj = (Ashes *)[NSEntityDescription insertNewObjectForEntityForName:@"Ashes" inManagedObjectContext:managedObjectContext];

[ashesObj setAshes_id:@""];
[ashesObj setArrangement_id:@"34"];
[ashesObj setCasket_order_date:@""];
[ashesObj setCasket_model:@""];
[ashesObj setCasket_supplier:@""];
//[ashesObj setAshes_address:@"N/A"];    (This one is causing problem)
[ashesObj setPostal_code:@"N/A"];
[ashesObj setName_client:@""];
[ashesObj setTelephone:@""];
[ashesObj setEmail:@""];

    NSError *error;

if (![managedObjectContext save:&error])
{
    NSLog(@"Problem saving: %@", [error localizedDescription]);
}

Upvotes: 1

Views: 1296

Answers (1)

Andy Obusek
Andy Obusek

Reputation: 12832

General best practice, ANYTIME you run into a EXEC_BAD_ACCESS immediately run your code (and the same click/code path) through Instruments using the tool Zombies.

Do this with that line of code uncommented. Your app will crash, but Instruments and Zombies will point you to the exact line of code that is causing the crash (which will be different than the one you have there).

Most likely you are accidentally over releasing an object, and for whatever reason, it's only being exposed when you execute the code above.

You can launch Instruments from XCode using the Product menu, and select Profile. Once Instruments starts up, you'll be prompted for the tool to use, select Zombies. Then once the simulator appears, execute the test case to reproduce the issue. Once the crash happens, you'll see info from Zombies.

Upvotes: 5

Related Questions