Question

When i try to use the MR_findAllSortedBy function with multiple keys, i get a keypath not found error. However, when i use this function with only one of the two keypaths it works. I can't figure why it doesn't work.

My code

-(void)performActionOnEachTrajetWithBlock:(void (^) (Trajet *trajet, NSArray *previousTrajets))actionBlock{

    NSMutableArray *previousTrajets = [NSMutableArray arrayWithArray:@[]];
    for (Trajet *trajet in [Trajet MR_findAllSortedBy:@"isActive, date" ascending:YES]){
        actionBlock(trajet, [NSArray arrayWithArray:previousTrajets]);
        [previousTrajets addObject:trajet];
    }
    return;
}

The error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath  date not found in entity <NSSQLEntity Trajet id=2>'

Thank you for helping me.

Was it helpful?

Solution

There must be no space in the first argument of

[Trajet MR_findAllSortedBy:@"isActive, date" ascending:YES]
     // remove this space ------------^

otherwise MagicalRecord will create a sort descriptor for the key " date" instead of "date".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top