Hmm.. Thought this would be easy but I'm stuck...

Here's what I've done:

- added the fake property BOOL needSaving
   @property(assign, nonatomic) BOOL needSaving;
  @synthesize needSaving;

- implemented keyPathsForValuesAffecting (I'm on Leopard)

+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key
{       
        NSSet* set = [super keyPathsForValuesAffectingValueForKey:key];

        if ([key isEqualToString:@"needSaving"]) {
                set = [set setByAddingObjectsFromSet:[NSSet setWithObjects:
                                                                        
@"lastName",
                                                                        
@"firstName",
                                                                          ...
                                                                         nil]];
        }
        
        return set;
}

Now, I just can't figure out how I should implement - (BOOL) needSaving! Setting it to NO in -init and implementing it like this obviously doesn't work:

- (BOOL) needSaving
{
        return YES;
}

Thanks,

Andre Masse


On Dec 19, 2008, at 12:35, Ken Thomases wrote:

On Dec 19, 2008, at 11:06 AM, Andre Masse wrote:

Let's say I have a class (called it Client) that has 25 fields and need to be notified when any of these is modified. Do I have to do - observeValueForKeyPath for each of the 25 fields?

You can add one "fake" property, use +keyPathsForValuesAffecting<Key> to tell KVO that all of your other keys affect the value of this one property, and then observe that one key.

On Tiger, you'd have to use +setKeys:triggerChangeNotificationsForDependentKey: to tell KVO about the dependencies.

Cheers,
Ken


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to