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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:16:01+00:00 2026-06-07T09:16:01+00:00

I am trying to find the index of a core data record using the

  • 0

I am trying to find the index of a core data record using the following code, where [self numItems] returns the number of records. The code takes about 0.2 seconds on average to execute. I am interested in speeding it up. Thanks in advance.

- (NSInteger) indexWithTaskID:(NSInteger)eventID
{
    for (NSInteger i=0;i<[self numItems];i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        NSManagedObject *managedObject = [self.fetchedResultsController
                                      objectAtIndexPath:indexPath];
        NSInteger myEventID = [(NSNumber *)[managedObject valueForKey:@"eventID"] intValue];

        if (myEventID == eventID) {
            return i;
        }
    }
    return -1;
}
  • 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-06-07T09:16:03+00:00Added an answer on June 7, 2026 at 9:16 am

    This is a little bit backward of what this is setup for, I’d try to avoid needing to find this index if you have much data, but if you really need to know the index then you might be stuck doing this search. If the predicate is sorted, you could do quite a bit better then a linear search, maybe a simple binary search could make enough improvement.

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

Sidebar

Related Questions

I'm trying to find out the index number of the last list item but
I am trying to find a clean way of referencing an array's index using
I'm using Lucene, and I'm trying to find a way to index and retrieve
I have the following regular expression: /(?<={index:)\d+(?=})/g I am trying to find index integer
I have a NSMutable Array and was trying to find the index number of
I am trying to find the index from an array using a loop function,
Using the index method, I'm trying to find if a value exists using a
I am trying to find the position/index of the current record within a group
searching around trying to find a way to add index on suffix of a
I'm trying to find out a way to know the index of a anchor

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.