NSManagedObjectModel
我有一个使用 Xcode GUI 创建的预先存在的文件。我想创建一个 Xcode 3.2 的 GUI 不支持的排序获取属性。我在创建我之前完成所有这些,因为我知道在对象图管理器开始使用它之后NSPersistentStoreCoordinator
你不能修改它。NSManagedObjectModel
我因此创建了NSFetchedPropertyDescription
:
NSManagedObjectModel *managedObjectModel = ... // fetch from my mainBundle
NSEntityDescription *fetchedPropertyEntityDescription = [entitiesByName objectForKey:@"MyEntity"];
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
[fetchRequest setEntity:fetchedPropertyEntityDescription];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"myPredicateProperty == $FETCH_SOURCE"]];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"mySortProperty" ascending:YES]]];
NSFetchedPropertyDescription *fetchedPropertyDescription = [[[NSFetchedPropertyDescription alloc] init] autorelease];
[fetchedPropertyDescription setFetchRequest:fetchRequest];
[fetchedPropertyDescription setName:@"myFetchedProperty"];
NSEntityDescription *entityDescription = [entitiesByName objectForKey:@"MyFetchSourceEntity"];
[entityDescription setProperties:[[entityDescription properties] arrayByAddingObject:fetchedPropertyDescription]];
当我打电话
[fetchedPropertyDescription setFetchRequest:fetchRequest];
我得到以下异常:
NSInvalidArgumentException: Can't use fetch request with fetched property description (entity model mismatch).