1
votes

I am using Magical Record .. I am using NSFetchRequest like:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(due_at < %@) AND complete == 0",startDate];
        NSArray *taskArray = [Task MR_findAllSortedBy:@"due_at" ascending:NO withPredicate:predicate];

i have logged Console and it is:

<NSFetchRequest: 0x16b239b0> (entity: Task; predicate: (due_at < CAST(415186806.000000, "NSDate") AND complete == 0); sortDescriptors: ((
    "(due_at, descending, caseInsensitiveCompare:)"
)); batch size: 20; type: NSManagedObjectResultType; )

It causes me an error of:

[__NSDate caseInsensitiveCompare:]: unrecognized selector sent to instance

How can i solve this issue..

1
what is the attribute type of due_at? My guess is that's a string, and you need to set it to date - casademora
There is something wrong with the sort descriptor as it looks like it's trying to use a string sort, rather than a numerical sort. - casademora
Yep, you're sorting with caseInsensitiveCompare: - and NSDate has only compare: method. Had the same error with NSUUID. Thank you @casedemora for your answer. - Nick

1 Answers

3
votes

This should help you work around this problem:

NSFetchRequest *request = [Task MR_requestAll];
NSSortDescriptor *sortByDueAtDate = [NSSortDescriptor sortDescriptorWithKey:@"due_at" ascending:NO selector:@selector(compare:)];
[request setSortDescriptors:@[sortByDueAtDate]];

NSArray *results = [Task MR_executeFetchRequest:request];
//continue on with results