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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:48:54+00:00 2026-05-23T19:48:54+00:00

While working on filtering my NSMutableDictionary based on user input, I created the following

  • 0

While working on filtering my NSMutableDictionary based on user input, I created the following code:

NSString *predicateString = [NSString stringWithFormat:@"SELF beginsWith[cd] %@", searchString];
NSPredicate *pred = [NSPredicate predicateWithFormat:predicateString];
NSArray *filteredKeys = [[myMutableDictionary allKeys] filteredArrayUsingPredicate:pred]; 

“searchString” is passed into the method with this definition:

(NSString*) searchString

This however resulted in the following exception:

…raised [ valueForUndefinedKey:]: this class is
not key value coding-compliant for the key…

The fix turned out to be:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF beginsWith[cd] %@", searchString];
NSArray *filteredKeys = [[myMutableDictionary allKeys] filteredArrayUsingPredicate:pred]; 

What I don’t understand, is why the latter worked, and the former threw the exception. I have read a little bit on key value coding, but I don’t understand how it applies here. (i.e. only by changing how the NSPredicate is defined) Can someone enlighten me?

Update:
In response to jtbandes comment, I went ahead and created a TestApp project to demo this problem. http://dl.dropbox.com/u/401317/TestApp1.tar.gz

  • 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-23T19:48:55+00:00Added an answer on May 23, 2026 at 7:48 pm

    The answer is in the predicate programming guide.

    String constants must be quoted within the expression—single and double quotes are both acceptable, … If you use variable substitution using %@ …, the quotation marks are added for you automatically. If you use string constants within your format string, you must quote them yourself

    [my emphasis]

    predicateWithFormat puts the quotes in for you, but stringWithFormat doesn’t. Your first example would probably work if you did this:

    NSString *predicateString = [NSString stringWithFormat:@"SELF beginsWith[cd] '%@'", searchString];
    //                                                                           ^  ^ single or double quotes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working with annotations I stumbled accross the following piece of code (it's the
While working with pointers i wrote the following code, int main() { int a[]={10,20,30,40,50};
While working on a project, I came across a JS-script created by a former
While working on an existing project I suddenly got the following error when trying
While working on a upgrade i happened to come across a code like this.
While working on my code lately, I've noticed that some of the memory usage
While working on my project, I created 3 mini-libraries (100-1000 lines). They are quite
While working on HTML, CSS (and more) like changing the code and refreshing the
While working on some graphics code a while back, I wrote Rect and Region
While working on a project I ran into the following Issue, in my CoreData

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.