【问题标题】:Keypath <transientproperty> not found in entity在实体中找不到密钥路径 <transientproperty>
【发布时间】:2013-04-05 00:30:12
【问题描述】:

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

我使用了下面的代码。但是它抛出了一个异常*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity &lt;NSSQLEntity Expense id=1&gt;'

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

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的声明和初始化

标签: ios objective-c core-data nssortdescriptor


【解决方案1】:

您问题的标题表明“dateSectionIdentifier”是一个瞬态属性。

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

参见“核心数据编程指南”中的Persistent Store Types and Behaviors 了解更多信息。

【讨论】:

  • 链接坏了;(
  • @Oriol:感谢您的通知,我已经更新了链接。
【解决方案2】:

我认为您会在子类中添加“dateSectionIdentifier”,但不会在 .xcdatamodelId 文件中更新。 交叉检查您是否在 .xcdatamodelId 文件中添加了“dateSectionIdentifier”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 2015-09-24
    • 2016-10-14
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多