Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

johnjay1776

macrumors member
Original poster
Jul 25, 2008
81
0
I've been reading through "Cocoa Programming For MAC OS X" by Hillegass. I'm on chapter 9 which covers the NSUndoManager and I've got a few questions about some of the material that I've come across both in this chapter and in chapter 8 (which covers the NSArrayController) as well. I think I get most of it but I have a few gaps in my understanding. If anyone on here would be so kind as to help a guy out, I'd be most appreciative.

First, with regard to the "setEmployees:" method which is written in chapter 9 as follows:

Code:
- (void)setEmployees:(NSMutableArray *)a
{
  
  if( a == employees)
	return;

  for(Person *person in employees) {
    [self stopObservingPerson:person];
  }

  [a retain];
  [employees release];
  employees = a;

  for(Person *person in employees){
    [self startObservingPerson:person];
  }

}
OK, I'm probably being dense here but what is the purpose of that method? He calls it in dealloc to deallocate the employees array. Is its sole purpose to assist
in deallocating the array? I understand why it's needed in that case but if you are
going to just use it to assist in deallocating the employees array, then why in the heck would you bother with telling the employees array to begin to start observing an empty array!? What's the purpose of that?

My next question is in concern to the two methods that he uses with the NSUndoManager. The only two methods that he adds to provide for use of the NSUndoManager are the following:

Code:
- (void)insertObject(Person *)p inEmployeesAtIndex:(int)index   and,
- (void)removeObjectFromEmployeesAtIndex:(int)index
What the heck? Why isn't there a

Code:
-(void)add(Person *)p toEmployeesAtIndex:(int)index

method? If the answer is, "Because such a method doesn't exist" then I'd ask, "Why did we connect the add employee button to the array controllers add: method earlier, then?" Does the array controller's add method call insert in some fashion?

Hope someone can point me in the right direction here. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.