我在使用启用ARC的NSOperation中保存NSManagedObjectContext时发现了一些问题.没有ARC,一切都很好.在保存期间始终提供EXC_BAD_ACCESS.代码如下所示:
//on the main thread
-(void)someFunc
{
array = ... //fetching an array of entities from a core data
for(SomeEntity * obj in array)
{
NSSomeOperation * op = [[NSSomeOperation alloc] initWithValue:[obj someField]];
//start an operation
}
}
//NSSomeOperation implementation
//...
- (void)main {
//some code
NSError * error = nil;
[mainContext lock];
if (![mainContext save:&error]) { //<--- HERE EXC_BAD_ACCESS
//process error
}
[mainContext unlock];
//some code
}
//...
Run Code Online (Sandbox Code Playgroud)
使用[mainContext setRetainsRegisteredObjects:YES]和objectWithID不能解决此问题.
EXC_BAD_ACCESS(代码= 1)
EXC_BAD_ACCESS(代码= 13)
-[__NSCFType contextDidSave:]: unrecognized selector sent …Run Code Online (Sandbox Code Playgroud) multithreading exc-bad-access core-data objective-c automatic-ref-counting