核心数据EXC_BAD_ACCESS KERN_PROTECTION_FAILURE

时间:2014-07-28 21:27:46

标签: ios core-data exc-bad-access nsmanagedobject

我有多个崩溃报告指向以下内容:

Thread : Crashed: NSOperationQueue 0x18c7fba0
0  libsystem_platform.dylib       0x38665a36 OSAtomicCompareAndSwap32Barrier + 13
1  libobjc.A.dylib                0x3805694b realizeClass(objc_class*) + 78
2  libobjc.A.dylib                0x38058797 lookUpImpOrForward + 74
3  libobjc.A.dylib                0x3805102b _class_lookupMethodAndLoadCache3 + 34
4  libobjc.A.dylib                0x38050df9 _objc_msgSend_uncached + 24
5  CoreData                       0x2da7b5bb -[_NSFaultingMutableSet copyWithZone:] + 238
6  MyApp                          0x0027226f -[Zoo getSortedCats] (Zoo.m:63)
7  MyApp                          0x00286955 -[BlockExecutionOperation main] (BlockExecutionOperation.m:30)
8  Foundation                     0x2e627aa5 -[__NSOperationInternal _start:] + 772
9  Foundation                     0x2e6cb96d __NSOQSchedule_f + 60
10 libdispatch.dylib              0x3853e4b7 _dispatch_async_redirect_invoke + 110
11 libdispatch.dylib              0x3853f7d9 _dispatch_root_queue_drain + 224
12 libdispatch.dylib              0x3853f9c5 _dispatch_worker_thread2 + 56
13 libsystem_pthread.dylib        0x38669dff _pthread_wqthread + 298

getSortedCats方法如下所示:

- (NSArray *)getSortedCats {
    NSSet* cats = [self.cats copy]; //this is line 63, where the crash occurs

    //do some sorting

    return sortedCats;

}

Zoo是一个带有cats属性的NSManagedObject子类:

@property (atomic, retain) NSSet *cats;

那么为什么自我崩溃?这个错误是什么意思?怎么避免?它只会偶尔发生一次,并且不可再现。

1 个答案:

答案 0 :(得分:4)

核心数据的特殊性。发送copy只会返回另一个NSFaultingMutableSet,而核心数据太过错误,无法做到这一点。

将其替换为[NSSet setWithSet:self.cats],您将面临较少的错误。