newbie question on 'Cocoa Programming for Mac OS X'
newbie question on 'Cocoa Programming for Mac OS X'
- Subject: newbie question on 'Cocoa Programming for Mac OS X'
- From: Richard Chamberlain <email@hidden>
- Date: Thu, 7 Feb 2002 23:23:01 +0000
Hi,
I'm just working my way through 'Cocoa Programming for Mac OS X' and
would like some feedback on something.
At the end of chapter 5 there are two challenges - the second one is to
delete multiple items out of a NSMutableArray, the issue being that as
you Enumerate through them the indexes shift.
I've solved it in the following way:
- (IBAction) deleteEmployee:(id) sender
{
NSNumber *anIndex;
int aRow;
NSMutableArray *tempArray=[[NSMutableArray alloc]init];
NSEnumerator *e=[tableView selectedRowEnumerator];
while (anIndex=[e nextObject]) {
aRow=[anIndex intValue];
[tempArray addObject:[employees objectAtIndex:aRow]];
}
[employees removeObjectsInArray:tempArray];
[tempArray release];
[self updateUI];
}
It seems to work - but I was curious if there was a better pattern, and
whether I've made any basic deallocation mistakes.
Sorry if this is off-topic but I don't know anywhere that it would be
more on topic.
Thanks,
Richard
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.