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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:27:44+00:00 2026-05-15T06:27:44+00:00

hello there and sorry for the stupid question but i think i might be

  • 0

hello there and sorry for the stupid question but i think i might be missing something simple here and can t figure it out myself.

i m trying to search a table view using the following code:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{

    NSString *predicateFormat = @"(name contains[c] %@) OR (age contains[c] %@)";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchString];
    self.fetchedResultsController = [self resetFetchedResultsController:predicate cached:NO];

    NSError *error = nil;
    [self.fetchedResultsController performFetch:&error];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

what i want to achieve is when the user searches the table to be able to search not only by “name” but with “age” as well!

my code above only searches the “name”

Am i missing something simple?

thank you for your time

  • 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-15T06:27:45+00:00Added an answer on May 15, 2026 at 6:27 am

    Instead of:

    NSString *predicateFormat = @"(name contains[c] %@) OR (age contains[c] %@)";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchString];
    

    You have three options:

    NSString *predicateFormat = @"(name contains[c] %@) OR (age contains[c] %@)";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchString, searchString];
    

    Or:

    NSString *predicateFormat = @"(name contains[c] %1$@) OR (age contains[c] %1$@)";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchString];
    

    Or:

    NSString *predicateFormat = @"(name contains[c] $SEARCH) OR (age contains[c] $SEARCH)";
    NSPredicate *template = [NSPredicate predicateWithFormat:predicateFormat];
    NSPredicate *predicate = [template predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:searchString forKey:@"SEARCH"]];
    

    The 3rd option is nice if you’re building a large predicate that has an unknown number of substitutions. The 2nd is probably the simplest in terms of not repeating yourself, but the 1st is easiest to understand.

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

Sidebar

Related Questions

Sorry for the unlearned nature of this question. If there's a simple answer, just
Note: I'm sorry if this is an extremely simple question but I'm somewhat obsessive
Hello sorry if this may be a stupid question, I am gonna try a
I’m a beginner in Ruby, so I’m sorry to ask something so simple, but
Hello there Stack Overflow, I hope you'll help me with my very first question
. Hello, I'm using jqueryui's datepicker, and it works great but there's a problem.
I know there are already some threads with this question, but none was helpful
Sorry for what is most likely a very 'newbie' question, but I'm having a
Sorry for the incredibly stupid question, I feel like in most circumstances I could
Sorry for the lame question. I am trying to run a simple getting started

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.