Re: change notification for dependent key between classes?
Re: change notification for dependent key between classes?
- Subject: Re: change notification for dependent key between classes?
- From: Alexander Lamb <email@hidden>
- Date: Mon, 12 Jun 2006 21:51:06 +0200
Ok, to go back to my post, I found some kind of solution but I have
no idea if this is the "correct" way of doing things:
In my task object, I implement this:
- (void)didChangeValueForKey:(NSString *)key withSetMutation:
(NSKeyValueSetMutationKind)mutationKind usingObjects:(NSSet *)objects
{
if([key isEqualToString:@"owner"])
{
[(LSProject *)[self valueForKey:@"project"]
didChangeValueForKey:@"peopleOnProject"];
}
}
This will basically say to all objects observing "peopleOnProject" to
call the method again.
Now, peopleOnProject is a to-many calculated relationship. I didn't
call the method usually used for to-many relations and I didn't call
"willChange" only the "didChange". I thought since it was a
calculated relationship, it was ok.
It seems to work. Is it the correct way?
Thanks,
Alex
--
Alexander Lamb
email@hidden
On Jun 12, 2006, at 3:42 PM, Alexander Lamb wrote:
Hello list,
I have a very simple model:
projects have many tasks
each task has one person (the owner of the task).
So in reverse, people have many tasks.
Basically, it is a many to many between projects and people with
tasks in the middle.
Now, the problem:
I want to have the list of people on a project. To do so, I
implemented in my project class:
- (NSSet *)peopleOnProject
{
return [self valueForKeyPath:@"email@hidden"];
}
This works fine.
In order to have peopleOnProject change notify my bindings, I added
in my project class:
+ (void)initialize
{
[self setKeys:[NSArray arrayWithObjects:@"tasks",nil]
triggerChangeNotificationsForDependentKey:@"peopleOnProject"];
}
So this works fine when I add or remove tasks to a project, the
"peopleOnProject" will be recalculated (and displayed).
Now, what if for a given task I change the owner. The "tasks"
attribute has not been changed to peopleOnProject will not trigger
a change.
Is there a simple way for doing a
triggerChangeNotificationForDependentKey on an attribute of a
second class?
Thanks,
Alex
--
Alexander Lamb
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden