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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:25:21+00:00 2026-05-20T00:25:21+00:00

I have several custom objects in an NSArray, I need to search through all

  • 0

I have several custom objects in an NSArray, I need to search through all the objects and fnd the index of the object that has a property which matches a string.
Should I be using a for each loop? I need it to be relatively fast to search each time a new character is entered in a textfield.

  • 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-20T00:25:22+00:00Added an answer on May 20, 2026 at 12:25 am

    NSPredicate is neat, but overkill (and it won’t give you the index of the found object; just the object itself).

    The paired array approach, which will work, feels odd to me (probably because it’s using a paired array).

    I would either use a for() loop (and break; when I found what I was looking for), or use a block enumerator:

    __block NSInteger indexOfMatchingObject = NSNotFound;
    [myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
      if ([[obj property] doesWhatImLookingFor]) {
        indexOfMatchingObject = idx;
        *stop = YES;
      }
    }];
    

    Or a slightly different variant:

    NSInteger indexOfMatchingObject = [myArray indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
      return ([[obj property] doesWhatImLookingFor]);
    }];
    

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

Sidebar

Related Questions

I have custom event that has several different subscribers who will all use the
I have several Entity Framework Code First DbContext objects that use a custom Initializer.
I created a custom object that has a Bitmap field. I'm drawing several of
I have a custom object type dependency property that is being populated at runtime.
I have Forms authentication and I need a custom object to be stored in
I have an ASP.NET web app that places several string data into an object
I have a UIView that gets loaded with several custom NSObjects (graphShape). Each graphShape
I have a django application with several views that accept json objects via POST
I have a custom NSManagedObject which has several properties. I alloc and init two
I have several web services in the same package that throw a custom exception.

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.