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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:58:03+00:00 2026-06-17T08:58:03+00:00

How do you make an NSPredicate that finds all objects in an array that

  • 0

How do you make an NSPredicate that finds all objects in an array that contain a certain letters?

NSMutableArray *testArray = [[NSMutableArray alloc] initWithObjects:@"abc",@"cba", @"bca", nil];

NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",@"abc"];

NSMutableArray *result = (NSMutableArray *)[testArray filteredArrayUsingPredicate: p];

Result only contains one object, @”abc”… I want it to catch all words that have “abc” in them. (e.g “cba”, “cba”, “lllllllllbbacllllll” etc)..

  • 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-17T08:58:04+00:00Added an answer on June 17, 2026 at 8:58 am

    There’s nothing wrong with the other answers. However, I wanted to suggest a different way to create the predicate: using a block.

    NSArray *testArray = @[@"abc", @"cba", @"cda"];
    NSArray *letters = @[@"a", @"b", @"c"];
    
    NSPredicate *p = [NSPredicate predicateWithBlock:^BOOL(id string, NSDictionary *bindings) {
        for ( NSString *letter in letters ) {
            NSStringCompareOptions options = NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch;
            if ( ! [string rangeOfString:letter options:options].length ) {
                return NO;
            }
        }
        return YES;
    }];
    NSArray *result = [testArray filteredArrayUsingPredicate:p];
    

    And just for the fun, you can also write the predicate with a subquery. This is less efficient but it’s the shorter solution.

    NSArray *testArray = @[@"abc", @"cba", @"bcda"];
    NSArray *letters = @[@"a", @"b", @"c"];
    
    NSPredicate *p = [NSPredicate predicateWithFormat:@"SUBQUERY(%@, $a, self CONTAINS[cd] $a)[SIZE] == %d", letters, letters.count];
    NSArray *result = [testArray filteredArrayUsingPredicate:p];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a predicate that includes special characters For example: [[myIngredients filteredSetUsingPredicate:[NSPredicate
The problem is that I don't know how can I make a NSPredicate that
I make an app that have to printing image. I need to print image
SOLUTION Make sure in the plist that the storyboard name is listed as the
I have an Array of MKAnnotation objects called arrAnnotations . I want to pick
Make javaScript and CSS External Source . Does that mean I should use JavaScript
I make an AJAX POST request to a PHP script on my server. That
To make sure all our customers receive the latest Silverlight App, we are placing
I have an array of dictionaries. I would like to filter that array by
Make sure you run outside of the IDE. That is key. -edit- I LOVE

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.