Keypath <transientproperty>在实体中找不到 [英] Keypath <transientproperty> not found in entity

查看:20
本文介绍了Keypath <transientproperty>在实体中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表格视图的部分标题中显示格式化的日期..

I want to show a formatted date in the section header of a table view..

我使用了以下代码.但它抛出了一个异常 *** 由于未捕获的异常NSInvalidArgumentException"而终止应用程序,原因:keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>".

I used the following code.but its throwing an exception *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>'.

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

guess the exception is coming when adding a sort descriptor.

NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20];
NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc] initWithKey:dateSectionIdentifier ascending:NO];
[sortDescriptors addObject:mainSortDescriptor];
[fetchRequest setSortDescriptors:sortDescriptors];

//费用.h

NSString *dateSectionIdentifier;

//费用.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;

}

推荐答案

你的问题标题表明dateSectionIdentifier"是一个transient属性.

The title of your question indicates that "dateSectionIdentifier" is a transient property.

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

You cannot use a transient property in a sort descriptor (or in a predicate) of a Core Data fetch request if SQLite is used as store type. That is a documented restriction, only persistent properties can be used.

请参阅持久存储类型和行为在核心数据编程指南"中了解更多信息.

See Persistent Store Types and Behaviors in the "Core Data Programming Guide" for more information.

这篇关于Keypath &lt;transientproperty&gt;在实体中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆