我目前正在使用MSCollectionViewLayout。最初的coredata模型是Event,它描述了一个瞬态属性" day"
//MSEvent.h
@interface MSEvent : NSManagedObject
@property (nonatomic, strong) NSDate *start;
- (NSDate *)day; // Derived attribute to make it easy to sort events into days by equality
@end
//MSEvent.m
- (NSDate *)day
{
return [self.start beginningOfDay];
}
原始代码使用RestKit,同时用瞬态属性" day"分隔部分。
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext
sectionNameKeyPath:@"day"
cacheName:nil];
这很好用。
这是我的问题:我使用自己的ManagedObjectContext而不是RestKit
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"day"
cacheName:nil];
我会在某个地方更新活动
event = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectContext];
[event setValue:eventData[@"startDate"] forKey:@"start"];
[managedObjectContext save:nil]; // here the problem occurs
我在最后一行收到错误消息:
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. [<NSManagedObject 0x9386a50> valueForUndefinedKey:]: the entity Event is not key value coding-compliant for the key "day".
添加&#34;日&#34;核心数据模型中的属性可以解决问题。
所以我的问题是:我认为NSManagedObject的瞬态属性可以提供额外的访问器而不会持久化实际值,就像类别一样。那么,当我尝试保存托管对象时,为什么会出现此错误?
答案 0 :(得分:0)
我自己修正了:我忘了在数据模型检查器中添加Class。