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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:19:22+00:00 2026-06-09T14:19:22+00:00

I have a large number of different NSObject types that all have different properties

  • 0

I have a large number of different NSObject types that all have different properties and I am trying to abstract out a single method that will allow me to filter the NSArrays of the objects by simply passing in an NSArray of properties I wish to filter on. The number keys I filter on vary from possibly 1 to whatever.

Here is an example of the filtering NSArray

NSArray *filterBy = [NSArray arrayWithObjects:
                       @"ManufacturerID",
                       @"CustomerNumber",nil];

These keys also exist in the objects of my NSArray I am filtering, so basically this would need to generate something like this:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K == %@ AND %K == %@",
                       [filterBy objectAtIndex:0], 
                       [items valueForKey: [filterBy objectAtindex:0],
                       [filterBy objectAtIndex:1], 
                       [items valueForKey: [filterBy objectAtIndex:1]];

Which would generate something like: ManufacturerID==18 AND CustomerNumber=='WE543'

Is it possible to do this?

  • 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-09T14:19:24+00:00Added an answer on June 9, 2026 at 2:19 pm

    This is easy. Check it out:

    NSMutableArray *subpredicates = [NSMutableArray array];
    for (NSString *filterKey in filterBy) {
      NSString *filterValue = [items valueForKey:filterKey];
      NSPredicate *p = [NSPredicate predicateWithFormat:@"%K = %@", filterKey, filterValue];
      [subpredicates addObject:p];
    }
    NSPredicate *final = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a large number of programmers on different platforms all using CVS. We
Dear Firends I have large number of forms on a single web page all
I have a large number of stored procs that all execute similar bits of
I have a large number of records (10,000, increasing every day) that essentially is
I have a large number of documents (mainly PDFs) that I want to index
I have a large number of csv files that look like this below: xxxxxxxx
I have a large number of C# WCF services that are being called by
We have a large number of data in many categories with many properties, e.g.
Basically, I have a large number of C structs to keep track of, that
I have a LINQ query that uses 1 table + a large number of

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.