On May 14, 2008, at 10:54 PM, Daniel Child wrote:
If I want to observe the property of an object, and in my case, it turns out that the M and C are collapsed into a model-controller, then it's basically a case of asking something to observe itself.

Well, it is sometimes desirable for an object to observe itself for changes to its properties. However, it is often not necessary. In particular, an object's properties should only be modified by messaging the object, which gives you a perfect way to "notice" that the change is being made -- right in the method which is invoked by the message.

For example, if your controller's number property is being changed, then something should be invoking its -setNumber: method. In that case, you can just add your code for coping with a change to that method:

- (void) setNumber:(NSNumber*)newNumber
{
        if (newNumber != number && ![number isEqualToNumber:newNumber])
        {
                [number release];
                number = [newNumber retain];
                // Add code to cope with a change in the number property here
        }
}


Can you be more specific about why you want your controller to observe its own number property? What are you trying to accomplish? I suspect there's another way to accomplish what you're interested in.


In other words, your "myFoo addObserver: self <THE CONTROLLER> forKeyPath: @"number" becomes....

- (void) awakeFromNib {
[self addOberver: self forKeyPath: @"number" options: 0 context: NULL];

There's a typo there.  You've missed the "s" in "addObserver".

}

I tried that and got the same message as before (<receiver> may not respond to addObserver), only this time the receiver is the controller instead of number.

Can you report the exact message you're getting? Is it a compile- time warning or a run-time exception?


Is it not possible to collapse M and C for a case where you want to track a simple text field. It seems it must be.

It is possible. We'll have to see what's going wrong in your particular case.

Cheers,
Ken
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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