Re: Can CoreData return only unique results of an attribute
Re: Can CoreData return only unique results of an attribute
- Subject: Re: Can CoreData return only unique results of an attribute
- From: Philip Bridson <email@hidden>
- Date: Wed, 27 Feb 2008 01:42:15 +0000
OK, I think I understand what you want to do now. You want to
retrieve the one set of values and then filter them based on their
individual values. Am I understanding right now?
If this is what you want to do then I am afraid you cannot do this
in interface builder. You would need to do this programatically. I
know it is long winded but this is my suggestion:
Create an object like so:
@interface MyObject : NSObject
{
NSManagedObjectContext *moc;
NSArray *contents;
NSMutableArray *filteredContents;
}
- (id)init;
@end
@implementation MyObject
-(id)init
{
self = [super init]
if(self)
{
moc = [[NSApp delegate] managedObjectContext]; //if this is where
it is...
NSFetchRequest *request = [[[NSFetchRequest alloc] init]
autorelease];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"FavoriteWebsites" inManagedObjectContext:moc];
[request setEntity:entity];
NSError *error = nil;
content = [managedObjectContext executeFetchRequest:request
error:&error];
//Then you need to filter the results into your new array...
filteredContents = [[NSMutableArray alloc] initWithCapacity:1];
[filteredContents addObject:([contents objectAtIndex:0]) ];
int contentCount = [contents count];
BOOL indenticleValueExists = FALSE;
for(int firstIndex = 0; index <= (contentCount - 1); index++)
{
filteredCount = [filteredContents count];
for(int secondIndex = 0; secondIndex <= (filteredCount - 1);
secondIndex++)
{
NSString *one = [[filteredContents objectAtIndex:secondIndex]
valueForKey@"url"];
NSString *two = [[contents objectAtIndex:firstIndex]
valueForKey@"url"];;
if([one compare:two] == 0)
identicleValueExists = TRUE;
}
if(identicleValueExists != TRUE)
[filteredContents addObject:([contents objectAtIndex:
firstIndex]) ];
}
}
return self;
}
@end
then in IB create a array controller and connect its content to
this object. Then you can bind a table to the new array controller
and the values in it will all be unique. If this is not what you
want at all then I'm sorry if I have gone off on a tangent.
Phil.
_______________________________________________
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