Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 657421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:49:20+00:00 2026-05-13T22:49:20+00:00

I have an NSMutableArray that is populated with objects of strings. For simplicity sake

  • 0

I have an NSMutableArray that is populated with objects of strings. For simplicity sake we’ll say that the objects are a person and each person object contains information about that person.

Thus I would have an NSMutableArray that is populated with person objects:

person.firstName
person.lastName
person.age
person.height

And so on.

The initial source of data comes from a web server and is populated when my application loads and completes it’s initialization with the server. Periodically my application polls the server for the latest list of names.

Currently I am creating an NSArray of the result set, emptying the NSMutableArray and then re-populating the NSMutableArray with NSArray results before destroying the NSArray object.

This seems inefficient to me on a few levels and also presents me with a problem losing table row references which I can work around, but might be creating more work for myself in doing so.

The inefficiency seems to be that I should be able to compare the two arrays and end up with a filtered NSArray. I could then add the filtered set to the NSMutableArray. This would mean that I can simply append new data to the NSMutableArray instead of throwing everything out and re-populating.

Conversely I would need to do the same filter in reverse to see if there are records that need removing from the NSMutableArray.

Is there any method to do this in a more efficient manner? Have I overlooked something in the docs some place that refers to a simpler technique?

I have a problem when I empty the NSMutableArray and re-populate in that any referencing tables lose their selected row state. I can track it and re-select it, but my theory is that using some form of compare and adding objects and removing objects instead of dealing with the whole array in one block might mean I keep my row reference (assuming the item isn’t deleted of course).

Any suggestions or help much appreciated.

Update

Would it be just as fast to do a fast enumeration over each comparing each line item as I go? It seems like an expensive operation, but with the last fast enumeration code it might be pretty efficient…

Solution

I ended up going with Abizem’s suggestion. Creating the mutable copy of the array and a copy of the object appears to be the slightly faster approach than using sbooth’s solution when dealing with large sets of data. Both worked great, I just got more of an edge by using the mutable copy approach. That being said, it did open my eyes up to NSSet where I hadn’t looked before.

Thanks for the feedback.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:49:20+00:00Added an answer on May 13, 2026 at 10:49 pm

    Two points.

    1. The new NSArray contains all the data you need to show. Which is why you are adding and deleting from the NSMutableArray to match the new one.
    2. You don’t want to lose the selected state of the rows in your table.

    Here’re my suggestions

    1. Rather than emptying the NSMutableArray and repopulating it with the new Array; why not create a mutableCopy of the NSArray and set that as your new NSMutableArray?
    2. Rather than worry about the order of the items (and hence the selected row number); how about creating a copy of the object that is selected, and after creating your new NSMutableArray as in step 1, find the matching object in the new array and set that as the selected row in the table using its new index.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 393k
  • Answers 393k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yep, it's there in PHP 5.2's cli SAPI. If you… May 15, 2026 at 2:05 am
  • Editorial Team
    Editorial Team added an answer This is what I did in a similar case, this… May 15, 2026 at 2:05 am
  • Editorial Team
    Editorial Team added an answer Your ScrollViewer is inside StackPanel which resizes to its content… May 15, 2026 at 2:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.