代码之家  ›  专栏  ›  技术社区  ›  Chandu

实体中找不到Keypath<transientproperty>

  •  13
  • Chandu  · 技术社区  · 11 年前

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

    我使用了以下代码。但它引发了一个异常 *** 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;
    
    }
    
    2 回复  |  直到 11 年前
        1
  •  31
  •   Martin R    8 年前

    问题的标题表明“dateSectionIdentifier”是 转瞬即逝的 所有物

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

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

        2
  •  0
  •   bharathi kumar    9 年前

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