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 6781823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:40:10+00:00 2026-05-26T16:40:10+00:00

I have two arrays, each containing strings. The first array is a list of

  • 0

I have two arrays, each containing strings. The first array is a list of words, the second array contains alternatives to those words in different languages.

The arrays are matched such that the word at index n in the second array is a translation of the word at index n in the first array.

The words and their translations are displayed in a table view. The user can filter the table view by entering text in a search field. When this is done, I create a filtered array from the first array like this:

- (void)filterContentForSearchText:(NSString*)searchText

[self.filteredarray removeAllObjects]; 
[firstarray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
 {
     if ([obj compare:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])] == NSOrderedSame)
     {
         idx= [firstarray indexOfObjectIdenticalTo:obj];
         NSUInteger maxindex = idx + 50;
         for (idx ; (idx < [firstarray count] && idx <= maxindex && idx!= NSNotFound); idx ++)
         {
             [self.filteredarray addObject:[firstarray objectAtIndex: idx]];
         }
         *stop = YES;
     }
 }];     

Then, when I am displaying the values in my table view, I use the following code. This is an exerpt from my cellForRowAtIndexPath method. I am trying to get the index from the original array using the object that has been added to the filtered array.

contentForThisRow = [self.filteredarray objectAtIndex:row];
NSUInteger index = [self.firstarray indexOfObjectIdenticalTo:contentForThisRow];
contentForThisRow2 = [self.secondarray objectAtIndex:index];

This works on the simulator, but on the device I will sometimes get repeats of the same entry from the second array. For example, my first array contains the word “hello” three consecutive times, at indexes x, y and z. My second array contains “hei”, “heisan” and “hoppsan”, which are all translations of “hello”, at indexes x, y and z.

On the simulator, I get three cells, each with a different translation. On the device, I get three cells, all with “hei”, the first translation. This does not happen for all repeated translations.

Why is this happening, and how can I get around it?

  • 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-26T16:40:11+00:00Added an answer on May 26, 2026 at 4:40 pm

    I think the problem is that iOS (on the device) may be using a slightly different optimisation to the emulator somewhere, either in NSString or NSArray. That is a guess.

    indexOfObjectIdenticalTo: returns the index of the first object that has the same memory address as the object you are passing in. On the phone it appears to have re-used the identical string objects in your first array when building the filtered array (possibly even when building firstArray), so you are getting the same index value back each time.

    A better solution would be to build your filtered array as an array of dictionaries, storing the values from the correct indexes of firstArray and secondArray at that point. You can then use these values directly when populating the cell instead of searching through both arrays again. This should also have some performance benefits.

    You would achieve this using the following code. First, inside your loop when you are building the filtered array, instead of adding the object from firstarray, do this:

    [self.filteredArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[firstarray objectAtIndex:idx],@"english",[secondarray objectAtIndex:idx],@"translated",nil];
    

    Then, in your cellForRowAtIndexPath, to get your two content variables:

    NSDictionary *rowData = [self.filteredarray objectAtIndex:row];
    contentForThisRow = [rowData objectForKey:@"english"];
    contentForThisRow2 = [rowData objectForKey:@"translated"];
    

    An even better solution would be to hold your data like this in the first place, and not try to keep two separate arrays synchronised. I imagine if you want to add or alter anything in your two separate files you could quickly get them out of step. However, I feel I’ve done enough for the day…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional JSON array where each element contains several attributes. The
I have two arrays containing the same elements, but in different orders, and I
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have two arrays built while parsing a text file. The first contains the
I have a function which takes two arrays containing the tokens/words of two texts
I have two arrays with different attributes for the objects contained in each. participants
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays. One contains id=>count and the other contains id=>name . I'm
I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] =>
I have two databases, each containing email addresses of users. I've written a script

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.