• 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: Automatic Key-Value Observing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic Key-Value Observing


  • Subject: Re: Automatic Key-Value Observing
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 18 Nov 2003 17:49:35 -0800

On Nov 18, 2003, at 2:59 PM, Joannou Ng wrote:
Correct me if I'm wrong. It seems automatic key-value observing when calling accessor methods only works if your accessor methods take parameters. For instance, the following when called doesn't invoke automatic key-value observing:
- (void)setName
Whereas, the following when called will invoke automatic key-value observing:
- (void)setName:(NSString *)newName

That's correct, as specified here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/Concepts/Compliant.html>

I hope I'm wrong.

I'm not sure why? If it's setting the value of a variable called 'name', a method such as
- (void)setName
violates the well-established Objective-C method naming conventions. Moreover in this case it's not clear to what exactly 'name' will be set.

There are a couple of options:
You could implement
- (void)setName:(id)something
and simply ignore 'something'. This is probably the least-good option.

You could probably implement
- (void)setName
with manual notifications (<http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueObserving/Concepts/AutoVsManual.html#//apple_ref/doc/uid/ 20001844/178876>
but your object will not be KVC compliant for 'name', so this may not work...

The best option is to implement the conventional accessor methods and rename your current 'setName' method, e.g.
- (void)createDefaultName // or whatever name is appropriate
and
- (void)setName:(NSString *)newName

createDefaultName should call
[self setName:...];
and you get the benefit of automatic notification.

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Automatic Key-Value Observing (From: Joannou Ng <email@hidden>)

  • Prev by Date: Re: Opening a NSOpenPanel in a secondary thread -> crash
  • Next by Date: Re: Updating the main menu
  • Previous by thread: Re: Automatic Key-Value Observing
  • Next by thread: Re: Automatic Key-Value Observing
  • Index(es):
    • Date
    • Thread