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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:52:45+00:00 2026-06-05T21:52:45+00:00

I have implemented a UISearchDisplayController that allows users to search a table. Currently the

  • 0

I have implemented a UISearchDisplayController that allows users to search a table. Currently the predicate I am using to search is as follows,

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"Name contains[cd] %@", searchText];

Now lets say a users searches for “beans, cooked” the corresponding matches are found in the table. But if the user enters the search text as “beans cooked” without the comma, there will be no matches found.

How can I re-write my predicate to “ignore” the commas when searching? In other words how can I re-write it so that it views “beans, cooked” being equal to “beans cooked” (NO COMMMA)?

  • 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-05T21:52:48+00:00Added an answer on June 5, 2026 at 9:52 pm

    First a disclaimer:

    I think that what you are trying to do is to add some “fuzzyness” to your search algorithm, seen that you want to make your match insensitive to certain differences in user input.

    Predicates (which are logic constructs) are by their very nature not fuzzy, so there is an underlying impedance mismatch between the problem and the tool chosen.

    Anyway, one way to go about it could be to add a method to your model object class.

    In this method, you can clean your name string so it only contains the most basic characters, say numbers, ascii letters and a space.

    Being totally deterministic, such a method is effectively a read-only string property on your object, and as such it can be used to match in predicates.

    Here is an implementation that removes punctuation, accents and diacritics:

    - (NSString *)simplifiedName
    {
        // First convert the name string to a pure ASCII string
        NSData *asciiData = [self.name dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
        NSString *asciiString = [[[NSString alloc] initWithData:asciiData encoding:NSASCIIStringEncoding] lowercaseString];
    
        // Define the characters that we will allow in our simplified name
        NSString *searchCharacters = @"0123456789 abcdefghijklmnopqrstuvwxyz";
    
        // Remove anything else
        NSString *regExPattern = [NSString stringWithFormat:@"[^%@]", searchCharacters];
    
        NSString *simplifiedName = [asciiString stringByReplacingOccurrencesOfString:regExPattern withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, asciiString.length)];
    
        return simplifiedName;
    }
    

    Now, a predicate could be made to search in the simplified name:

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"self.simplifiedName = %@", searchString];
    

    You would of course want to clean the search string using the same algorithm used to clean the name, so it would probably be a good idea to factor it out into a general method to be used in both places.

    Last, the simplifiedName method can also be added by implementing a category to the model object class so you don’t have to modify its code, which is handy in case your object class is defined in an auto-generated file by Core Data.

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

Sidebar

Related Questions

I have implemented a SearchBar using a UISearchDisplayController and a UITableView to display the
I have implemented a table view with multiple threads. Currently when a user taps
I have implemented a DAL using Rob Conery's spin on the repository pattern (from
I have implemented changing the brightness of an image using uislider in iPhone without
I have implemented a simple appmod that handle WebSockets and echo back the messages.
I have implemented a ViewFlipper with 8 child view in my application as follows.
I have implemented SSO authentication using the sourceforge spnego project . This is my
I have implemented Solr search in one of my .net application. Everything working fine
I have implemented a simple D3.js line chart that can be zoomed and panned.
I have implemented audio playback using AVPlayer, playing a remote mp3 url. I want

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.