• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Implementing Smart Collections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Custom NSView That is iChat Chat Log Like
  • Next by Date: Batch process fro website
  • Previous by thread: Implementing Smart Collections
  • Next by thread: Call of super from a custom NSCell in a custom NSControl
  • Index(es):
    • Date
    • Thread