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

The Archive Base Latest Questions

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

Using Core Data w/a sqlite store on iPhone…. I’ve got a bunch of comic

  • 0

Using Core Data w/a sqlite store on iPhone…. I’ve got a bunch of comic book image entities, each with a string that includes the comic’s issue#, e.g.: image.imageTitle = @"Issue 12: Special Edition";

Part of the UI allows the user to type in an issue number to jump to the next issue. My initial code for this was sloooooooow because imageAtIndex: queries Core Data for one object at a time. Over several hundred issues, it could take upwards of 40 seconds just to get through the first loop!

Slow Code:

 // Seek forward from the next page to the right
 for (i = currentPage + 1; i < [self numberOfPages]; i++) {
  iterationString = [[self imageAtIndex:i] imageTitle];
  iterationNumber = [[iterationString stringByTrimmingCharactersInSet:nonDigits] intValue];

  if (issueNumber == iterationNumber) {
   keepLooking = NO;
   break;
  }
 }
 // If nothing was found to the right, seek forward from 0 to the current page
 if (i == [self numberOfPages] && keepLooking) {
  for (i = 0 ; i < currentPage; i++) {
   iterationString = [[self imageAtIndex:i] imageTitle];
   iterationNumber = [[iterationString stringByTrimmingCharactersInSet:nonDigits] intValue];

   if (issueNumber == iterationNumber) {
    keepLooking = NO;
    break;
   }
  }
 }

Hoping for a much more efficient solution, I decided to try making a direct query on Core Data like so:

    NSString *issueNumber = @"12";
    NSString *issueWithWordBoundaries = [NSString stringWithFormat:@"\\b%@\\b",issueNumber];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(groupID == %@) AND (imageTitle CONTAINS %@)", groupID, issueWithWordBoundaries];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
 NSEntityDescription *entity = [NSEntityDescription entityForName:@"CBImage" inManagedObjectContext:self.managedObjectContext];
 [fetchRequest setEntity:entity];

 [fetchRequest setPredicate:predicate];
 [fetchRequest setIncludesSubentities:NO]; // Not sure if this is needed, but just in case....

 // Execute the fetch
 NSError *error = nil;
 NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

    // [fetchedImages count] == 0

Between the Predicate Programming Guide and the ICU regex specs, I figured the \b’s would help prevent a search for 12 returning 120, 121, 122, etc. Instead, it doesn’t return anything from the store at all!

On the other hand, if I leave off the word boundaries and search instead for stringWithFormat:@"%@",issueNumber, I get dozens of managed objects returned, from 12 to 129 to 412.

My best guess at this point is that I’ve run into one of Core Data’s Constraints and Limitations. If not, what am I doing wrong? If so, is there a workaround that offers both an exact match and the speed of a single fetch?

  • 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-14T23:25:20+00:00Added an answer on May 14, 2026 at 11:25 pm

    Turns out the word boundaries were a red herring: My problem was a variant on this issue: The regex couldn’t succeed without some wild cards to match the bits I didn’t care about in the imageTitles.

    The general case solution to finding an exact phrase using NSPredicate is therefore:

    NSString *exactPhrase = @"phrase_you_hope_to_find_in_another_string";
    NSString *regularExpression = [NSString stringWithFormat:@".*\\b%@\\b.*",exactPhrase];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stringToSearch CONTAINS %@", exactPhrase];
    // Assuming a string or an entity's string attribute named stringToSearch
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 451k
  • Answers 451k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have a look at http://emmense.com/php-twitter/; it uses curl to communicate… May 15, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer I just fixed some simple mistakes in your code ..… May 15, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer You are looking for substring_index UPDATE table SET column =… May 15, 2026 at 8:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.