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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:00:05+00:00 2026-05-19T00:00:05+00:00

This question is based off of the same app/source from my previous question which

  • 0

This question is based off of the same app/source from my previous question which can be found here:

How to manage memory using classes in Objective-C?

I have a nested array which looks something like this when printed out (I only copied and pasted a brief part of it).

(
        (
        <Term: 0x4256420>,
        <Term: 0x420fa40>,
        <Term: 0x4257bd0>,
        <Term: 0x4257cf0>,
        <Term: 0x4257d90>,
        <Term: 0x4257e30>
    ),
        (
        <Term: 0x4257e50>,
        <Term: 0x4257f90>,
        <Term: 0x4257fb0>,
        <Term: 0x42580e0>,
        <Term: 0x4258170>,
        <Term: 0x4258210>,
        <Term: 0x4258230>,
        <Term: 0x4258360>,
        <Term: 0x4258400>,
        <Term: 0x42584a0>,
        <Term: 0x4258540>,
        <Term: 0x42585e0>,
        <Term: 0x4258670>,
        <Term: 0x4258710>
    ),

And here is my code for the search part of my table:

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section 
{
    // Normal table
    if (aTableView == self.tableView) return [[self.sectionArray objectAtIndex:section] count];

    // Search table
    //NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", self.searchBar.text];
    //self.filteredArray = [self.crayonColors filteredArrayUsingPredicate:predicate];
 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@", self.searchBar.text];
    self.filteredArray = [[self.sectionArray objectAtIndex:section] filteredArrayUsingPredicate:predicate];


    return self.filteredArray.count;
}

I am getting the error that I cannot allocate enough room which means that I must be doing something wrong, I just cannot figure out what.

The commented out portion of the search part in the above method works but crayonColors is just a simple NSMutableDictionary of NSStrings and does not have arrays nested inside of it.

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-19T00:00:06+00:00Added an answer on May 19, 2026 at 12:00 am

    As far as I’m aware, you can’t do this with a single predicate. However, you can do it with a key-path operator and a predicate in two separate calls.

    So, you have an array of arrays of terms. You want a single array of terms where its name contains ‘A’ (for example). Here’s what you do:

    NSArray * allTerms = ...; //your array of arrays of terms
    NSArray * collapsedTerms = [allTerms valueForKeyPath:@"@unionOfArrays.self"];
    
    NSPredicate * filter = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", @"A"];
    NSArray * filteredTerms = [collapsedTerms filteredArrayUsingPredicate:filter];
    

    The magic here is the valueForKeyPath: bit. The @unionOfArrays operator takes an array of arrays of objects, and returns an array of objects. Here’s what it’s doing: The NSArray is going to break the keypath up by ., giving it @unionOfArrays and self. It’s going to recurse and invoke valueForKeyPath: on itself using the second bit (self), and it’s going to get back an array of arrays. It’s then going to mash all those arrays together into a single array, ignoring duplicates. (If you want to remove duplicates, use @distinctUnionOfArrays instead)

    Once we have that array of objects, we can then filter it normally using a simple name CONTAINS 'blah' predicate.

    (I thought I might be able to get this to work using a SUBQUERY, but that’s a strange beast and nothing was immediately obvious to me.)

    For the super intrepid, you could do this with a single method call using KickingBear’s collection extensions (available here), but I would strongly advise against using hacks like that in a production setting. 🙂

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

Sidebar

Related Questions

No related questions found

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.