如何以编程方式创建NSFetchedPropertyDescription?
|
我有一个用Xcode GUI创建的ѭ0。我想创建一个排序的访存属性,Xcode 3.2的GUI不支持该属性。在创建ѭ1之前,我会做所有这些事情,因为我知道在对象图管理器开始使用ѭ0之后,您将无法对其进行修改。因此,我创建了
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).
没有找到相关结果
已邀请:
2 个回复
唤副埂侧壬
埃庐
上设置
之前将
添加到
中。 正确的步骤如下: