Benefit from undo/redo stuff


#1

Hi,
do I get it right:
When I press the Add button, the add: method of the array controller will start and has a default behavior. I guess it will just use the addObject: method of the content array. But before, it will look after the method insertObject:inContentArrayNameAtIndex:. If it exists, use this one instead of the addObject: method. That means, that if I want to use undo and redo, I can write these methods, and can add undo/redo capabilities. BUT: The disadvantage is that I have to add/remove the objects from my array manually. Am I right?

And another question about the proxy object. On page 149, there is that line:

id arrayProxy = [playlist mutableArrayValueForKey:@"songs"];

For me it seems a little dispensable. Why not:

id arrayProxy = [playlist songs];

or, if I really want to use KVC:

id arrayProxy = [playlist valueForKey:@"songs"];

By the way, I do not see a big benefit using KVC. Is it “just” bindings?


#2

[quote=“DaPhil”]Hi,
do I get it right:
When I press the Add button, the add: method of the array controller will start and has a default behavior. I guess it will just use the addObject: method of the content array. But before, it will look after the method insertObject:inContentArrayNameAtIndex:. If it exists, use this one instead of the addObject: method. That means, that if I want to use undo and redo, I can write these methods, and can add undo/redo capabilities. BUT: The disadvantage is that I have to add/remove the objects from my array manually. Am I right?[/quote]

Yes.

[quote=“DaPhil”]And another question about the proxy object. On page 149, there is that line:

id arrayProxy = [playlist mutableArrayValueForKey:@"songs"];

For me it seems a little dispensable. Why not:

id arrayProxy = [playlist songs];

or, if I really want to use KVC:

id arrayProxy = [playlist valueForKey:@"songs"];

By the way, I do not see a big benefit using KVC. Is it “just” bindings?[/quote]

-mutableArrayValueForKey:@“songs” and -songs/-valueForKey:@“songs” return two different things. The latter two do not return an array proxy; they return the actual array. The array proxy is an object that behaves like an mutable array, but is actually calling methods like -insertObject:inSongsAtIndex:, if they exist.

If the array controller manipulated the NSMutableArray directly (using addObject:), we wouldn’t have a way of observing those changes from our controller object (RMDocument).

Adam


#3

[quote=“AdamPreble”]
-mutableArrayValueForKey:@“songs” and -songs/-valueForKey:@“songs” return two different things. The latter two do not return an array proxy; they return the actual array. The array proxy is an object that behaves like an mutable array, but is actually calling methods like -insertObject:inSongsAtIndex:, if they exist.

If the array controller manipulated the NSMutableArray directly (using addObject:), we wouldn’t have a way of observing those changes from our controller object (RMDocument).
Adam[/quote]
I don’t see what an arrayProxy is for… I could override the add: and remove: methods to achieve the same!? What is the advantage of an arrayProxy?