Re: CoreData: sorting on a computed attribute
Re: CoreData: sorting on a computed attribute
- Subject: Re: CoreData: sorting on a computed attribute
- From: Volker in Lists <email@hidden>
- Date: Fri, 15 Mar 2013 11:04:21 +0100
Hi Laurent,
when I faced a similar problem - in my case I needed to filter data acquired fromCoreData in a TableView for a field value that wasn't part of the model, but existed as an ivar in the NSManagedObject subclass - I used the following:
[self.sessionController setFilterPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return [(Session*)evaluatedObject fileLocationInvalid];
}]];
Depending on the complexity of the calculation and the impact on performance you may want to do similar.
You may be able to produce a similar result by using a block as comparator function for the descriptor. Or write your own comparator function to compare the calculated values. In both cases you won't need to create a persistent attribute, but do the calculation in the sort descriptor block or compare function.
My 2cents,
Volker
Am 14.03.2013 um 18:11 schrieb Laurent Daudelin:
> I have a need to sort a CoreData table on one attribute in a table that needs to be derived from a calculation. I read about "Non-Standard Persistent Attributes" and did google and the only way I found to make it work is according to the following:
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden