RE: Implementing Smart Collections
RE: Implementing Smart Collections
- Subject: RE: Implementing Smart Collections
- From: Drew McCormack <email@hidden>
- Date: Sat, 24 Feb 2007 13:07:28 +0100
I found a solution to this which is quite simple. In case it helps
someone, here it is:
and refresh the collection if an object changes that has the entity
corresponding to the collection. For example, to check updated
objects:
- (void)itemsDidChange:(NSNotification *)notification {
NSEnumerator *enumerator;
id object;
BOOL refresh = NO;
NSEntityDescription *entity = [[self
valueForKey:@"fetchRequest"] entity];
NSSet *updated = [[notification userInfo]
objectForKey:NSUpdatedObjectsKey];
enumerator = [updated objectEnumerator];
while ((refresh == NO) && (object = [enumerator nextObject])) {
if ([object entity] == entity) {
refresh = YES;
}
}
The solution is to use the predicate of the smart collection to see
if the updated objects change the collection members. Pretty obvious
in hindsight.
Here is the code:
enumerator = [updated objectEnumerator];
while ((refresh == NO) && (object = [enumerator nextObject])) {
if ([object entity] == entity) {
BOOL itemShouldBeInCollection = [[self
valueForKey:@"predicate"] evaluateWithObject:object];
if ( [knowledgeItems containsObject:object] ) {
if ( !itemShouldBeInCollection ) refresh = YES;
}
else {
if ( itemShouldBeInCollection ) refresh = YES;
}
}
}
---------------------------------------------------------
Drew McCormack
www.macanics.net
www.macresearch.org
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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