• 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: changeKeyPath method documentation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: changeKeyPath method documentation


  • Subject: Re: changeKeyPath method documentation
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 11 Jan 2009 20:21:18 -0800

On Jan 11, 2009, at 05:25, Russell Martin wrote:

Here's the source of changeKeyPath:
- (void)changeKeyPath:(NSString *)keyPath
            ofObject:(id)obj
             toValue:(id)newValue
{
	// setValue:forKeyPath: will cause the key-value observing method
	// to be called, which takes care of the undo stuff
	[obj setValue:newValue forKeyPath:keyPath];
}

OK, so you've found the definition of the method. You certainly can't tell from this definition alone whether it's overriding something else, but you've eliminated the possibility of its overriding something else in your (or Hillegass's) code by searching for it, and you've eliminated the possibility of its overriding something in the Cocoa frameworks (or something similar, like being a delegate method) by checking the documentation. So it's just a method.


I tried this. 'Jump to definition' stays right where I started, at the one and only implementation of changeKeyPath in my MyDocument.m file. Also, searching for changeKeyPath in all of my project file shows only the one instance in MyDocument.m. This is why I was thinking that I was overriding a super's method or implementing a delegate method.


...

Nope. Not getting a compile error. I even cleaned all targets and rebuilt just to make sure. The program builds and runs and does what Hillegass says it will do. He's got an email address listed in the book for feedback, I guess I should give him some because to a complete beginner (which is what this book is for), it's a complete mystery as to why:

a) I don't have to provide any earlier declaration of changeKeyPath

This is true, under certain conditions. If nothing in the .m file containing the definition refers to it *before* the definition, and nothing in any other .m file refers to it at all, then there's no need to have a separate declaration ("stub"). [This is a useful technique for methods that are private to the .m file, BTW, since it runs no risk of exposing the method to the outside world.] As I noted before, that's true of *any* definition in C, whether it's a variable or a function (or a method in Objective-C). If you need to use the method elsewhere, just add a declaration in the @interface of the .h file corresponding to the .m file.


b) no other method calls it in the program

Could be. Since this a method you (or Hillegass) wrote, it won't be called unless you write code to call it.


c) I just added a an NSLog call to it, built, put the program through its paces and it never seems to get called.

See (b).

d) I just commented it out and it doesn't seem to affect the program's functionality at all

See (b).

e) I might have just been wasting everyone's time, and if so, please let me apologize for that.

Not a problem, and I don't think you were so terribly tangled up after all. If you can work out where you're supposed to call this method (and you'll have to refer to Hillegass's book for that -- maybe he doesn't have you use it until a later section), you'll work out whether you're going to need the declaration in the .h file, or whether you can take the shortcut of omitting the .h file declaration.




_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: changeKeyPath method documentation
      • From: Alan Staniforth <email@hidden>
References: 
 >Re: changeKeyPath method documentation (From: Russell Martin <email@hidden>)

  • Prev by Date: Re: Implementing an Inspector similar to the one in IB.
  • Next by Date: Re: How can i read the "iTunes Library" file?
  • Previous by thread: Re: changeKeyPath method documentation
  • Next by thread: Re: changeKeyPath method documentation
  • Index(es):
    • Date
    • Thread