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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:12:50+00:00 2026-05-29T15:12:50+00:00

EDIT: I’m adding a new rough table model for comment. Is this what you

  • 0

EDIT: I’m adding a new rough table model for comment. Is this what you had in mind?

enter image description here

I’m still trying to work out a search filter for a core data set. I got stuck here, so I’m approaching the problem differently.

First, what I’m trying to do is the following:

  1. Iterate through all objects (NSManageObject *object in tableViewModel.items)

  2. Extract all the subentity objects for each ‘object’ and validate against search term.

  3. If the search term does exist in the subentity, then add ‘object’ to ‘autoSearchResults’ (if it doesn’t already exist there)

My code is as follows:

NSLog(@"%s", __FUNCTION__);

    NSMutableArray *startArray = [NSMutableArray array];
    NSMutableArray *filteredArray = [NSMutableArray array];

    for (NSManagedObject *object in tableViewModel.items) 
    {
        NSLog(@"1 ");

        NSSet *set1 = [object valueForKeyPath:@"people.name"];
        NSString *str1 = [[set1 allObjects] componentsJoinedByString:@", "];
        peopleSet = str1;

        NSLog (@"peopleSet is %@ ", peopleSet);

        NSLog(@"2 ");
        NSSet *set2 = [object valueForKeyPath:@"place.name"];
        NSString *str2 = [[set2 allObjects] componentsJoinedByString:@", "];        
        placeSet = str2;

        NSLog(@"3 ");
        NSSet *set3 = [object valueForKeyPath:@"keyword.name"];
        NSString *str3 = [[set3 allObjects] componentsJoinedByString:@", "];        
        keywordSet = str3;

        NSLog(@"4 ");
        NSSet *set4 = [object valueForKeyPath:@"type.name"];
        NSString *str4 = [[set4 allObjects] componentsJoinedByString:@", "];        
        typeSet = str4;     

        NSLog(@"5 ");
        NSSet *set5 = [object valueForKeyPath:@"symbol.name"];
        NSString *str5 = [[set5 allObjects] componentsJoinedByString:@", "];        
        symbolSet = str5;

        NSLog(@"6 ");

        NSLog (@"searchText is: %@ ", searchText);

        myPredicate = [NSPredicate predicateWithFormat:@"(peopleSet contains[cd] %@) || (placeSet contains[cd] %@) || (keywordSet contains[cd] %@) || (typeSet contains[cd] %@) || (symbolSet contains[cd] %@)", searchText, searchText, searchText, searchText, searchText ];

        NSLog(@"7 ");       
        if (myPredicate) {
            [startArray addObject:object];
            NSLog (@"startArray.count is %i ", startArray.count);
        }

        NSLog(@"8 ");
        NSLog (@"startArray.count is %i ", startArray.count);
        /*
        if (startArray.count == 0)
        {
            NSLog(@"0");
        } else {            
            NSLog(@"9 ");
            [filteredArray addObject: startArray];
            NSLog(@"10 ");
            [startArray removeAllObjects];
            NSLog(@"11 ");
        }
        */

    }       


    //autoSearchResults = filteredArray;
    return autoSearchResults;
}

In my testing, I have 3 objects, one with the person.name “me”, one with “you”, and one with “Mother”. All the other fields are blank in all objects.

Right now, I’m stopping to see how many objects are selected for each search. Essentially, the searchText is found but ignored. That is, the routine sees that the searchText contains “me” for example, but still adds an Object where the actual text is “You”.

I would appreciate any help.. If it would help to reduce this example, please let me know..

  • 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-29T15:12:51+00:00Added an answer on May 29, 2026 at 3:12 pm

    The most egregiously wrong thing about this code is that you’re not actually using the predicate you create. In order to test an object against a predicate, call evaluateWithObject: on the predicate, passing in the object to test.

    But that still won’t work, because it doesn’t know what “peopleSet” and all those other strings are: you can’t use a local variable as if it were a keypath.

    Finally, this structure doesn’t really take advantage of the power of predicates; you’re using a predicate like a regex. To actually filter an object collection, use a method such as filteredSetUsingPredicate: on the collection itself instead of testing every object.

    Of course, this will require you to create a transient property on your managed object model to store the concatenated list of names, but if you do that correctly, you’ll see a performance boost when doing this kind of filtering.

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

Sidebar

Related Questions

Edit: The below question was answered by this . I have a new updated
EDIT: I think I've worked something out. - This character - ’ - seems
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
EDIT: There's now a doc page on this so this question is irrelevant, also
edit alright, I guess C is painful in nature--Just, this part, is particularly painful.
Edit: I would like to model a 1 to 0:1 relationship between User and
Edit: I'm looking for solution for this question now also with other programming languages.
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
EDIT After staring at this for 2 days, I do see one issue. I

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.