1

我最初认为这是一个面向多线程的崩溃,所以我使用 MOC 的 performBlock 和 performBlockAndWait 方法将所有实际的核心数据工作转移到了主线程。

所做的只是将崩溃从我合并的地方移到我称之为“保存”的地方。

在这一点上,我什至不知道从哪里开始检查错误。

这不是多线程——所有核心数据工作都被导出到主线程。

我重新创建了所有子类,因此(理论上)它不应该是子类与其所代表的实体之间的不匹配。

更烦人的是,除了现在在主块上执行之外,我用来更新核心数据模型的代码在几个版本中都没有改变,这表明我的代码深处存在某种严重的缺陷,而且没有任何线索它在哪里或如何找到它。

任何可以帮助我追踪此崩溃的信息或建议将不胜感激。

CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  NSManagedObjects of entity 'AdBlock' do not support -mutableSetValueForKey: for the property 'currentlyValidAds' with userInfo (null)

2012-09-25 14:50:13.250 CoreApp[1173:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSManagedObjects of entity 'AdBlock' do not support -mutableSetValueForKey: for the property 'currentlyValidAds''

AdBlock 与 Advertisement 类具有多对多、可选、有序、瞬态关系“currentValidAds”。作为对评论的回应,我检查了反向关系,这是一对一的、可选的瞬态关系。(我现在已将其更新为多对多、选项、有序、瞬态关系,但错误仍然存​​在)。

根据要求,生成的代码:

AdBlock.h:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Advertisement;

@interface AdBlock : NSManagedObject

@property (nonatomic, retain) NSNumber * adIndex;
@property (nonatomic, retain) NSNumber * block_id;
@property (nonatomic, retain) NSNumber * seedBlock;
@property (nonatomic, retain) NSSet *ads;
@property (nonatomic, retain) NSOrderedSet *currentlyValidAds;
@end

@interface AdBlock (CoreDataGeneratedAccessors)

- (void)addAdsObject:(Advertisement *)value;
- (void)removeAdsObject:(Advertisement *)value;
- (void)addAds:(NSSet *)values;
- (void)removeAds:(NSSet *)values;

- (void)insertObject:(Advertisement *)value inCurrentlyValidAdsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromCurrentlyValidAdsAtIndex:(NSUInteger)idx;
- (void)insertCurrentlyValidAds:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeCurrentlyValidAdsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInCurrentlyValidAdsAtIndex:(NSUInteger)idx withObject:(Advertisement *)value;
- (void)replaceCurrentlyValidAdsAtIndexes:(NSIndexSet *)indexes withCurrentlyValidAds:(NSArray *)values;
- (void)addCurrentlyValidAdsObject:(Advertisement *)value;
- (void)removeCurrentlyValidAdsObject:(Advertisement *)value;
- (void)addCurrentlyValidAds:(NSOrderedSet *)values;
- (void)removeCurrentlyValidAds:(NSOrderedSet *)values;
@end


#import "AdBlock.h"
#import "Advertisement.h"

AdBlock.m

@implementation AdBlock

@dynamic adIndex;
@dynamic block_id;
@dynamic seedBlock;
@dynamic ads;
@dynamic currentlyValidAds;

@end

还有一个类别提供了一些逻辑——主要是更新当前有效的广告——但它没有在导致崩溃的代码块中使用,所以我不包括它。

编辑:

我还没有回答潜在的问题,但我已经通过手动将我删除的任何对象的瞬态值设置为 nil 来解决崩溃错误。不知道为什么这有帮助......只是由于睡眠不足而产生的一个随机想法。

4

0 回答 0