Implementing Smart Collections
Implementing Smart Collections
- Subject: Implementing Smart Collections
- From: Drew McCormack <email@hidden>
- Date: Sat, 24 Feb 2007 12:17:15 +0100
I've implemented smart collections based on Core Recipes. I register
for notifications for changes made to the managed object context:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemsDidChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:ManagedObjectContext()];
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 problem is, any update of any property of an object triggers a
refresh, even if the property is not relevant to the smart
collection. This is causing me the following problem: I have a text
view that continuously updates the model, and pressing any key causes
the smart collection to refresh, thereby causing the array controller
to update its selection, and thereby the text view to lose focus.
What I really need to do is only refresh my smart collections when
certain properties are changed, but there doesn't seem to be any way
to find out what changed from the notification object passed above.
Is there a straightforward solution to this, or do I just have to
give up on having continuously updating text views?
Drew McCormack
---------------------------------------------------------
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