• 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
Re: Adding objects to NSMutableArray out of order?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding objects to NSMutableArray out of order?


  • Subject: Re: Adding objects to NSMutableArray out of order?
  • From: Jonathan Hess <email@hidden>
  • Date: Mon, 4 May 2009 18:16:36 -0700

Hey Colin -

It sounds like you are going to get results 1-n, out of order, here's what I would do:

- (void)start {
    myArray = [[NSMutableArray alloc] init];
    for(NSInteger idx = 0; idx <= n; idx += 1) {
        [myArray addObject:[NSNull null]];
    }
}

- (void)processResult:(id)result forPosition:(NSInteger)position {
    [myArray replaceObjectAtIndex:position withObject:result];
}

Compiled in mail -
Jon Hess

On May 4, 2009, at 4:50 PM, Colin Cornaby wrote:

I'm dealing with some code that returns results out of order, but the results contain the proper index. In the end, I'd like to put them all into an NSArray, but unlike a C array, NSArray doesn't seem to allow me to simply reserve X number of slots and fill the slots as the results come in.

One workaround I can see is to actually store the results in a C array, and then initialize the NSArray from the C array. I could also write an algorithm that would try to rearrange the NSMutableArray as results come back, but that seems more complicate. Initializing from a C array looks like the best bet, but this is a commonly called function of the software that is performance sensitive, and could be dealing with large sets of data, so I was wondering about the overhead of this approach.

Has anyone here run into a similar situation?

Thanks,
Colin

_______________________________________________

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

_______________________________________________

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


References: 
 >Adding objects to NSMutableArray out of order? (From: Colin Cornaby <email@hidden>)

  • Prev by Date: Re: Adding objects to NSMutableArray out of order?
  • Next by Date: Re: Adding objects to NSMutableArray out of order?
  • Previous by thread: Re: Adding objects to NSMutableArray out of order?
  • Next by thread: Re: Adding objects to NSMutableArray out of order?
  • Index(es):
    • Date
    • Thread