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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:59:55+00:00 2026-05-12T15:59:55+00:00

In one of the code examples from Apple, they give an example of searching:

  • 0

In one of the code examples from Apple, they give an example of searching:

for (Person *person in personsOfInterest)
{
    NSComparisonResult nameResult = [person.name compare:searchText
            options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)
            range:NSMakeRange(0, [searchText length])];

    if (nameResult == NSOrderedSame)
    {
        [self.filteredListContent addObject:person];
    }
}

Unfortunately, this search will only match the text at the start. If you search for “John”, it will match “John Smith” and “Johnny Rotten” but not “Peach John” or “The John”.

Is there any way to change it so it finds the search text anywhere in the name? Thanks.

  • 1 1 Answer
  • 1 View
  • 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-12T15:59:56+00:00Added an answer on May 12, 2026 at 3:59 pm

    Try using rangeOfString:options: instead:

    for (Person *person in personsOfInterest) {
        NSRange r = [person.name rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
    
        if (r.location != NSNotFound)
        {
                [self.filteredListContent addObject:person];
        }
    }
    

    Another way you could accomplish this is by using an NSPredicate:

    NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", searchText];
    //the c and d options are for case and diacritic insensitivity
    //now you have to do some dancing, because it looks like self.filteredListContent is an NSMutableArray:
    self.filteredListContent = [[[personsOfInterest filteredArrayUsingPredicate:namePredicate] mutableCopy] autorelease];
    
    
    //OR YOU CAN DO THIS:
    [self.filteredListContent addObjectsFromArray:[personsOfInterest filteredArrayUsingPredicate:namePredicate]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've implemented a bit of code from one of the many Apple code examples,
From code how can we know which interfaces one class implements? Example: interface IDrink
I was looking at the TableSearch example code from Apple. It looks like that
example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the
For example… This PHP code <?php echo '<html>'; echo '<body>'; echo '<h1>Header One</h1>'; echo
i can't understand one thing. In code, for example: $filePath = 'http://wwww.server.com/file.flv'; if( file_exist($filePath)
does any one know if, for example, I'm writing in c++ the following code:
The iTunes mini-player (to give just one example) supports click-through where the application isn't
I've been using this method (I think I got it from one of Apple's
is there any development environments that allow you to have one code base that

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.