开发者

Inserting entity in CoreData and EXC_BAD_ACCESS signal

I am writi开发者_运维技巧ng a program that synchronizes with a server. Synchronization is run in foreground but using LRResty and delegates to get the responses. Randomly, while I run the synchronization, I get EXC_BAD_ACCESS signal running this code or some other insertion/relationship adding in CoreData:

WorkoutExerciseSet *set = [NSEntityDescription insertNewObjectForEntityForName:@"WorkoutExerciseSet" inManagedObjectContext:mObjContext];

Therefore I was thinking the error is given because this code isn't actually run on the main thread. Could that be the reason? Which is the best way to solve it?


The only possible source of EXC_BAD_ACCESS in the line of code given is that the mObjContext has a nil value. You are losing your NSManagedObjectContext object somewhere along the line.

Based on that one line of code, you are probably not using assessors correctly. The managed object context is almost always an attribute of the object holding the insertion code so the line should probably look like:

WorkoutExerciseSet *set = [NSEntityDescription insertNewObjectForEntityForName:@"WorkoutExerciseSet" inManagedObjectContext:self.mObjContext];

... to make sure the context object is properly accessed. Likewise, when you set the attribute value it should be:

self.mObjContext=someManagedObjectContext;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜