Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

ios - Keypath <transientproperty> not found in entity

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

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];

//Expense.h

NSString *dateSectionIdentifier;

//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;

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...