--- On Sat, 1/10/09, Quincey Morris <[email protected]> wrote:
 
> > So, are you saying that changeKeyPath isn't an
> override or a delegate method? If so, then why don't I
> have to put a stub in the .h file? I thought that unless I
> was implementing an override or delegate method that the
> stub in the .h was required. Is my thinking wrong on this?
> And, if so, when is the stub in the .h file required and not
> required?
> 
> I think maybe you have two different things tangled up.

I think I might have things tangled up too, and I appreciate anyone's attempts 
at straightening me out.
 
> 1. Your 'changeKeyPath' method isn't part of
> the Cocoa frameworks. That's why looking for it in the
> Cocoa documentation produces no results. It's something
> that Hillegass designed and wrote, so presumably its source
> code is given to you to use or copy.

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];
}
 
> 2. Methods are just like everything else in C -- they must
> be *either* declared *or* defined before they can be
> referenced (or both). Declarations (what you're calling
> "stubs") are typically placed in .h files, but not
> always. (Sometimes they're earlier in the .m file where
> they're used.)
> 
> If your file compiles without errors, then if you
> right-click 'changeKeyPath' and choose "Jump to
> Definition", you should get a popup menu with at least
> two entries. One will take you to the place where the method
> is declared (in some .h file, probably) and the other will
> take you to the place where the method is defined (in some
> .m file).

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.
 
> If you're getting a compile error for
> 'changeKeyPath', then presumably you missed a step
> somewhere in Hillegass's instructions for setting up
> your project (e.g. you missed a #import at the top of the .m
> file).

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

b) no other method calls it in the program

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

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

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

Thanks again to those of you who took the time to try and help, it was helpful.


      
_______________________________________________

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