Re: changeKeyPath method documentation
Re: changeKeyPath method documentation
- Subject: Re: changeKeyPath method documentation
- From: Alan Staniforth <email@hidden>
- Date: Mon, 12 Jan 2009 22:03:05 +0000
At 20:21 -0800 11/1/09, Quincey Morris wrote:
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've dug out my exercise code for the RaiseMan example and so far as
I can see -changeKeyPath is called from -observeValueForKeyPath in
MyDocument.m:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSUndoManager *undo = [self undoManager];
id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
// NSNull objects are used to represent nil in a dictionary
if (oldValue == [NSNull null]) {
oldValue = nil;
}
NSLog(@"oldValue = %@", oldValue);
[[undo prepareWithInvocationTarget:self] changeKeyPath:keyPath
ofObject:object
toValue:oldValue];
[undo setActionName:@"Edit"];
}
I seem to recall that Undo functionality is added well on in the
chapter so maybe you just haven't been asked to create this method
yet.
HTH
-Alan.
--
Alan Staniforth ** email@hidden
"Meum est propositum/In taberna mori,/Ut sint vina proxima/Morientis ori."
-- Anon.
_______________________________________________
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