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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:20:50+00:00 2026-05-23T16:20:50+00:00

I can use [NSArray indexOfObject: NSString] to get an index of my search for

  • 0

I can use [NSArray indexOfObject: NSString] to get an index of my search for 1 item. But what can I use or do to get an array of returned indices from my search?

thanks

  • 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-23T16:20:51+00:00Added an answer on May 23, 2026 at 4:20 pm

    To get multiple indices, you can use indexesOfObjectsPassingTest::

    // a single element to search for
    id target;
    // multiple elements to search for
    NSArray *targets;
    ...
    // every index of the repeating element 'target'
    NSIndexSet *targetIndices = [array indexesOfObjectsPassingTest:^ BOOL (id obj, NSUInteger idx, BOOL *stop) {
            return [obj isEqual:target];
        }];
    
    // every index of every element of 'targets'
    NSIndexSet *targetsIndices = [array indexesOfObjectsPassingTest:^ BOOL (id obj, NSUInteger idx, BOOL *stop) {
            return [targets containsObject:obj];
        }];
    

    Support for blocks were added in iOS 4. If you need to support earlier versions of iOS, indexesOfObjectsPassingTest: isn’t an option. Instead, you can use indexOfObject:inRange: to roll your own method:

    @interface NSArray (indexesOfObject)
    -(NSIndexSet *)indexesOfObject:(id)target;
    @end
    
    @implementation NSArray (indexesOfObject)
    -(NSIndexSet *)indexesOfObject:(id)target {
        NSRange range = NSMakeRange(0, [self count]);
        NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
        NSUInteger idx;
        while (range.length && NSNotFound != (idx = [self indexOfObject:target inRange:range])) {
            [indexes addIndex: idx];
            range.length -= idx + 1 - range.location;
            range.location = idx + 1;
        }
        return [indexes autorelease];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there anyway i can use search bar on the nsmutable array . i
You can use SelectFolder() to get a folder or GetOpenFolderitem(filter as string) to get
You can use App.config; but it only supports key/value pairs. You can use .Net
I can use FlashWindowEx to make a window flash in the taskbar, but what
can i use like this r not for (NSString *string in userInfo){ lblUserName.text =
I have a search string, where people can use quotes to group phrases together,
I can use vi{ and va{ to select C++ code blocks. It helps me
I can use the regex comparing a comma delimited list of GUID against a
You can use more than one css class in an HTML tag in current
You can use a standard dot notation or a method call in Objective-C to

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.