Reputation: 11753
I have the following problem with Core Data.
On an entity containing a one-to-one relationship called Next, I do some actions using this Next relationship to go from one instance to the following one. This works fine.
Using the following code :
error=nil;
[context save:&error];
NSLog(@"Error:%@",error);
I check under gdb that my data are saved without any problem.
Here is when troubles are coming. After I close the simulator (using Command-Q); when I restart the application I get this error (in gdb): Program received signal: “EXC_BAD_ACCESS”. It happens when trying to execute the following line of code :
item=[item valueForKey:@"Next"];
And at some point I have seen in the debugger some thing like : this class is not key value coding-compliant for the key Next
Since things work out perfectly before closing the app with Command-Q, my code must not be 100% wrong, but obviously it also has some bugs. Is there any obvious reason why this could be?
Actually, in case this was not clear. I have made a tiny sample project to illustrate my problem in case one has time and interest to look at it. It shows a counter going from 1 to 3 and it has 2 buttons to move the counter backward and forward. But I am just not sure on how to upload such a sample project on this site.
At this point I tried to start using Instruments hoping to find some bugs, but up to now with no success at all. The program working at one stage and not after (even my tiny sample test) I suspect some tricky issue due to a mistake in the way I use Core Data.
Upvotes: 1
Views: 494
Reputation: 26652
Most likely the line where you hit EXC_BAD_ACCESS
is a red herring. Although, it could offer some clues.
Do think about what you're doing here specifically:
item=[item valueForKey:@"Next"];
What happens to the original item
that you are assigning the results of valueForKey
to? If it's not an autoreleased object then you have a problem right there.
Anyway, first off the bat, checkout the issue I've just mentioned. Next, run the Analyzer. Then, if you've fixed all that and theres still a problem, start running the Leaks tool in Instruments.
For details, along with the excellent link on what causes these errors and step by step instructions for how to fix, have a look at answers to these questions:
finding reason for EXC_BAD_ACCESS - in Xcode4
Random EXC_BAD_ACCESS in a place that it cannot happen
Upvotes: 1