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

  • Home
  • SEARCH
  • 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 6741239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:04+00:00 2026-05-26T11:42:04+00:00

I have a nsmutablearray which I add object to it in a for loop

  • 0

I have a nsmutablearray which I add object to it in a for loop from a nsarray. I want it to add object until it reaches NSNotFound in indexOfObject: from NSArray.
The array is inside a for loop to extract string from every index.

My code:

NSInteger untilNotFound = NSNotFound;
NSUInteger index = [array indexOfObject:string];

for (index; index < untilNotFound; index ++)
{           
    [self.mutablearray addObject:[array objectAtIndex: index]];
}

Edit:

for (string in array)
{
NSComparisonResult *result = [string compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) 
                              range:NSMakeRange(0, [searchText length])];

if (result == NSOrderedSame)
{
            NSInteger index;
            for (index =[array indexOfObject:string]; (index < [array count] && index < 100 && index!= NSNotFound); index ++)
            {
                [self.mutablearray addObject:[array objectAtIndex: index]];         

            }

break;

}

}

EDIT.

My previous code that works, it is inside if (result == NSOrderedSame) I just wonder if there is any nicer and easier and performance-friendly solution to extract indexes just before it reaches NSNotFound:

        NSUInteger new = [array indexOfObject:string];

        NSString *last = [array lastObject];

        NSUInteger total = [array indexOfObject:last];

        NSUInteger newmax = new + 10;

        NSUInteger totalminus = total - 11;


        if (newmax <= totalminus )

        {

            [self.mutablearray addObject:string];

            [self.mutablearray addObject:[array objectAtIndex:new + 1]];

            [self.mutablearray addObject:[array objectAtIndex:new + 2]];
            [self.mutablearray addObject:[array objectAtIndex:new + 3]];
            [self.mutablearray addObject:[array objectAtIndex:new + 4]];
            [self.mutablearray addObject:[array objectAtIndex:new + 5]];
            [self.mutablearray addObject:[array objectAtIndex:new + 6]];
            [self.mutablearray addObject:[array objectAtIndex:new + 7]];
            [self.mutablearray addObject:[array objectAtIndex:new + 8]];
            [self.mutablearray addObject:[array objectAtIndex:new + 9]];
            [self.mutablearray addObject:[array objectAtIndex:new + 10]];
        }

        else 
        {
            [self.mutablearray addObject:string];
        }
  • 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-26T11:42:04+00:00Added an answer on May 26, 2026 at 11:42 am

    Looks like you’re trying to do a cumulative subset. Try this:

    for(NSInteger index = [array indexOfObject: string]; ((index <  [array count]) &&
                                                          (index <= 100)           &&
                                                          (index != NSNotFound))   ;  index++)
    {
        [self.mutablearray addObject: [array objectAtIndex: index]];
    }
    

    Or, if you’re just doing a strict subset, try this:

    NSInteger startIndex = [array indexOfObject: string];
    NSInteger endIndex = MIN([array count], 100);
    if(startIndex != NSNotFound)
    {
        self.mutablearray = [array subarrayWithRange: NSMakeRange(startIndex, endIndex)] mutableCopy];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class named Profile and a NSMutableArray which I add the
iPhone Development: I want to have an infinite loop constantly checking an NSMutableArray and
I have a class Test which has an array of Foos. I want to
I have a NSMutableArray: NSMutableArray *temp = //get list from somewhere. Now there is
I have an NSMutableArray. It's members eventually become members of an array instance in
I am getting errors when trying to add items to a NSMutableArray which is
I have an NSMutableArray which has about 18 objects. They are in a specific
I have created NSMutale Array in HeroListViewController . I want use it in another
I'm trying to make an array of objects (animalImages) from a plist file which
quick question regarding Array's in xcode. I have ht efollowing code, which is supposed

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.