• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
newbie question on 'Cocoa Programming for Mac OS X'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: newbie question on 'Cocoa Programming for Mac OS X'
      • From: email@hidden
  • Prev by Date: How do I open an NSDrawer in awakeFromNib?
  • Next by Date: Re: Removing table rows while editing?
  • Previous by thread: Re: How do I open an NSDrawer in awakeFromNib?
  • Next by thread: Re: newbie question on 'Cocoa Programming for Mac OS X'
  • Index(es):
    • Date
    • Thread