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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:11:19+00:00 2026-05-27T08:11:19+00:00

I am trying to filter my array with two entities within an object like

  • 0

I am trying to filter my array with two entities within an object like I have a Person object in which I have name, address, number, email, etc. I am trying to filter my array list of objects with just name and number. How can this be achieved with using NSPredicate?

  • 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-27T08:11:20+00:00Added an answer on May 27, 2026 at 8:11 am

    Create the predicate (the following assumes that your Person class has name and number string properties):

    NSString *nameFilter = @"Steve*";
    NSString *numberFilter = @"555-*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(name like %@) or (number like %@)", nameFilter, numberFilter];
    

    Then, filter the array (this assumes you have an NSArray of Person objects):

    NSArray *personArray = /* obtain from somewhere */;
    NSArray *filtered = [personArray filteredArrayUsingPredicate:pred];
    

    The result will be an array that contains Person objects whose name could be “Steve”, “Steven” etc, and whose number starts with 555-.

    Edit

    What you’re saying doesn’t really make sense. You can’t remove properties from a class (or rather, you shouldn’t). If you just want an array that contains only the names and numbers you’ll have to iterate through the array of Person objects:

    NSMutableArray *result = [NSMutableArray array];
    
    for (Person *p in personArray)
        [result addObject:[NSString stringWithFormat:"%@ : %@", [p name], [p number]]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to filter a two-dimensional array with VBScript but VBScript's built-in filter function
I have an array of checkboxes, and trying to filter them, but when no
I am trying to filter an IEnumerable object of the duplicate values, so I
I am trying to filter items with a stored procedure using like . The
I'm trying to filter some XML in JavaScript using E4X and have some specific
I am trying to filter for an object that has a Title field, and
I have two models, Project and Category, which have a many-to-many relationship between them.
I have two arrays, each containing strings. The first array is a list of
I'm trying to write some Erlang that would filter an array in the form:
I'm trying to create a filter. I have a function that returns an NSArray

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.