在实体中找不到Keypath <transientproperty>

Cha*_*ndu 11 core-data objective-c nssortdescriptor ios

我想在表视图的节头中显示格式化日期.

我使用了以下代码.但它抛出异常*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>'.

猜测添加排序描述符时会出现异常.

NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20];
NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc] initWithKey:dateSectionIdentifier ascending:NO];
[sortDescriptors addObject:mainSortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];
Run Code Online (Sandbox Code Playgroud)

//Expense.h

NSString *dateSectionIdentifier;
Run Code Online (Sandbox Code Playgroud)

//Expense.m

@dynamic dateSectionIdentifier

-(NSString *)dateSectionIdentifier{
[self willAccessValueForKey:@"dateSectionIdentifier"];
NSString *tempDate = [self primitiveDateSectionIdentifier];
[self didAccessValueForKey:@"dateSectionIdentifier"];
if(!tempDate){
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"d MMMM yyyy"];
    tempDate = [dateFormatter stringFromDate:[self date]];
    [self setPrimitiveDateSectionIdentifier:tempDate];
    [dateFormatter release];
}
return tempDate;

}
Run Code Online (Sandbox Code Playgroud)

Mar*_*n R 29

您的问题的标题表明"dateSectionIdentifier"是一个瞬态属性.

如果将SQLite用作存储类型,则不能在Core Data获取请求的排序描述符(或谓词)中使用transient属性.这是一个记录的限制,只能使用持久属性.

有关详细信息,请参阅"核心数据编程指南"中的持久存储类型和行为.