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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:30+00:00 2026-05-25T21:53:30+00:00

I want to search data from nsdictionary based on different criteria.Say I have 4

  • 0

I want to search data from nsdictionary based on different criteria.Say I have 4 keys and user can search based on any number of keys ex:4,3 etc..Ex:I have dictionary containing keys(First Name,Last Name,Address,Phone Number).Now user can search based on any key say First Name and Last Name, or only First Name.I am using NSPredicate to search.My problem is how to create dynamic nspredicate?If I provide empty string in

[NSPredicate predicateWithFormat:@"FirstName  CONTAINS[cd] %@ AND LastNAme  CONTAINS[cd] %@ AND Address  CONTAINS[cd] %@ AND PhoneNumber  CONTAINS[cd] %@",firstname,lastname,addr,phone]

It does not give any result.How can I achieve this?or I have to create multiple nspredicate based on fields user has provide?

Thanks in advance!

  • 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-25T21:53:30+00:00Added an answer on May 25, 2026 at 9:53 pm

    You can build the predicate programmatically:

    NSArray *keysToSearch = [NSArray arrayWithObjects:@"FirstName", @"LastName", @"Address", nil];
    NSString *searchString = @"Bob";
    
    NSMutableArray *subPredicates = [NSMutableArray array];
    for (NSString *key in keysToSearch) {
      NSPredicate *p = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", key, searchString];
      [subPredicates addObject:];
    }
    
    NSPredicate *filter = [NSCompoundPredicate andPredicateWithSubPredicates:subPredicates];
    

    Then use filter to filter your dictionaries.

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

Sidebar

Related Questions

I want to create search interface to search data from GAE datastore? Can i
I have five columns and i want to search data from five columns but
I want to search a user from LDAP and after getting the user I
Hello everyone i want search data from invoices and client by today date I'm
I do have 8 tables. when a query fires from search page data from
I have to extract data from a saved search and drop each column into
I have got a PHP/HTML page where I want to fetch data from but
I have a system that fetches its data from different databases on the same
For example, I want to search/insert/get/delete data from database and I'm working with wcf
I want to search data within the given date range. I have a database

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.