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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:05:13+00:00 2026-06-02T00:05:13+00:00

I have a pList of strings which I’m bundling into an NSMutable Array. NSString

  • 0

I have a pList of strings which I’m bundling into an NSMutable Array.

NSString *path = [[NSBundle mainBundle] pathForResource:@"small" ofType:@"plist"];
_availableWords = [[NSMutableArray alloc]initWithContentsOfFile:path];

I want to compare each character in the strings to a specified character and use the results to create a new array.

I’m able to filter on the first and last characters using the below

NSPredicate *filter = [NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@", @"B"];

NSPredicate *filter = [NSPredicate predicateWithFormat:@"SELF endswith[cd] %@", @"B"];

but when I try to check the characters in between using the characterAtIndex method I get an error.

NSPredicate *filter = [NSPredicate predicateWithFormat:@"SELF characterAtIndex:%i LIKE[cd] %@", 3, @"B"];

I know I could probably do a loop to loop through each word checking the characters but using NSPredicate is so much tidier and should be much better performance considering the list of strings can be quite large (over 100,000).

Can anyone show me the proper syntax for using characterAtIndex with NSPredicate or have any other solution ideas?

Update: Based on Kens answer below I am now using the below code to check characters outside of the first and last characters. For example the below checks the 4th character.

NSArray *matches = [_availableWords objectsAtIndexes:[_availableWords indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
    return (BOOL)([obj characterAtIndex:3] == 'R');
}]];

However, when I go to inspect the matches array in the debugger I see the below error

matches NSArray *   0x06a67ba0 @"Variable is not a CFArray"

and no objects in the array. Based on the sample data in short.pList I’d expect to see one object in the array.

Thanks in advance for any help,
Derm

  • 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-02T00:05:14+00:00Added an answer on June 2, 2026 at 12:05 am

    The built in predicates don’t support such an operation. However, you can build a predicate which evaluates a block:

    NSPredicate* filter = [NSPredicate predicateWithBlock:^(id evaluatedObject, NSDictionary *bindings){
        return (BOOL)([evaluatedObject characterAtIndex:3] == 'B');
    }];
    

    Or, if you’re just going to turn around and filter an array with this predicate, you can cut out the middleman and use a block to identify elements of an array directly:

    NSArray* matches = [array objectsAtIndexes:[array indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
        return (BOOL)([obj characterAtIndex:3] == 'B');
    }]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a plist which I have put into and array, which looks
I have a plist which contains an array of NSDictionary 's which represent a
I have a plist file which is an array of dictionaries. Where each dictionary
If I have a plist which is structured like this: Root Array Item 0
I have a NSMutableArray which i am initializing from a plist with strings. but
I have an array of strings which i am already showing in my uitableview.
i have a plist that's at its root an array with dictonaries inside it.
I have a django app that I made and have implemented a plist into
I have a configuration class in my objective-c app which reads a PLIST file
I just upgraded to the latest 4.3 Xcode. I have my plist.which is preprocessed

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.