I have this instance method that returns a list of distinct values.
-(void)test
{
return [self valueForKeyPath:@"@distinctUnionOfObjects.values"];
}
It works for one especific object, but i have a lot of objects.
I am thinking about a class method that returns something like
SELECT DISTINCT column_name(s) FROM table_name
What is the best way to do this? And how can i have do it whith a class method?
Edit:
It works now! Thanks, AKV!
@interface
+(NSArray *)fetchAll; // array with all managed objects.
+(NSSet *)myMethod;
@implementation
+(NSSet *)myMethod
{
return [NSSet setWithArray:[[MyClass fetchAll] valueForKey:@"myField"]];
}
Create a set, and find the distinct values as :