Keypath <transientproperty> not found in entity
Asked Answered
M

2

13

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;

}
Minutiae answered 12/4, 2013 at 12:57 Comment(1)
Show us the declaration and initialization of dateSectionIdentifierSimonides
M
31

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.

Mendelssohn answered 12/4, 2013 at 13:30 Comment(2)
the link is broken ;(D
@Oriol: Thanks for the notice, I have updated the link.Mendelssohn
K
0

I think you would have added "dateSectionIdentifier" in the subclass, but not updated in the .xcdatamodelId file. Cross check to see whether you have added "dateSectionIdentifier" in .xcdatamodelId file or not.

Kimmie answered 4/9, 2015 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.