ios - 在实体中找不到键路径 <transientproperty>

标签 ios objective-c core-data nssortdescriptor

我想在 TableView 的节标题中显示格式化日期..

我使用了下面的代码。但是它抛出了一个异常 *** 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];

//费用.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 属性。

如果将 SQLite 用作存储类型,则不能在核心数据提取请求的排序描述符(或谓词)中使用 transient 属性。这是记录在案的限制,只能使用持久属性。

参见 Persistent Store Types and Behaviors在《核心数据编程指南》中 获取更多信息。

关于ios - 在实体中找不到键路径 <transientproperty>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15972040/

相关文章:

javascript - 在 ios 或 android 中使用 safari 或 chrome 播放 mp3 文件

ios - 多行文本的 LayoutManager boundingRectForGlyphRange

ios - Swift:为什么闭包函数调用迟了

ios - Cordova后台模式地理位置iOS 10

iOS - 无约束的可滑动 UITableCells

ios - NSPredicate 按名称传递 "multiple"参数 [在 Swift 中]

Swift - 将核心数据与 Cocoa 结合使用

ios - 从方案中删除实体后的核心数据迁移

Javascriptcore ios调用类方法

objective-c - 在 macOS 的 Cocoa 应用程序中,我使用 NSFileWrapper 将包保存到磁盘。如何让查找器显示我的 bundle 的正确图标?