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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:33+00:00 2026-05-28T08:26:33+00:00

I have a core data application that uses an NSPredicate in one of its

  • 0

I have a core data application that uses an NSPredicate in one of its fetch requests. That predicate is defined as follows:

NSDictionary *teamsParams = [NSDictionary dictionaryWithObject:teamArray forKey:@"TEAMS"]; 
NSPredicate *predicate = [[NSPredicate predicateWithFormat:@"(homeTeam IN $TEAMS) AND (awayTeam IN $TEAMS)"] predicateWithSubstitutionVariables:teamsParams]

I apply this predicate to a fetch request and run it and it works as I expect: At least it works with the limited amount of data I have in my data store at this time.

I am now trying to write a set of unit tests for this code. To do this I am using OCMock to create an NSManagedObjectContext with its executeFetchRequest stubbed out with my own test implementation:

id contextMock = [OCMockObject mockForClass:[NSManagedObjectContext class]];
[[[contextMock stub] andCall:@selector(stubbedExecuteFetchRequest:error:) onObject:self] executeFetchRequest:[OCMArg any] error:(NSError * __autoreleasing *) [OCMArg anyPointer]];

- (NSArray *)stubbedExecuteFetchRequest:(NSFetchRequest *)request error:(NSError **)error  {    
    // allGames is an array containing a list of "mocked" game instances
    NSArray *result = [allGames filteredArrayUsingPredicate:[request predicate]];
    return result;
}

So basically, I am trying to take the NSPredicate that was defined to run against a core data fetch request, and to run it against an array of mocked objects. The mocked objects all implement the homeTeam and awayTeams methods so as far as the predicate is concerned, this should work. Unfortunately, when running filteredArrayUsingPredicate against my dta array, it returns an empty array. I’m really stuck trying to figure this out, and I’m not sure how to effectively debug this one.

So I have two questions here, really:

  1. Is there a reason I’m missing here why using filteredArrayUsingPredicate against array of mock objects (instances of an NSProxy subclass) that implement the properties referenced in the predicate?
  2. Assuming there’s no obvious reasons, can anyone suggest an effective way of debugging this to see what it is filteredArrayUsingPredicate is evaluating here and why its failing for me?

Thanks for any help you can provide

  • 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-28T08:26:33+00:00Added an answer on May 28, 2026 at 8:26 am

    I have managed to figure out most of what was happening here. The primary problem I was encountering here is that when I use filteredArrayUsingPredicate with a predicate containing a term such as “homeTeam”, my array objects are evaluated against this predicate by calling their valueForKey method with a key of “homeTeam”. I had expected this valueForKey invocation to return the value of the homeTeam accessor method, but for some reason that is not happening with my mock objects (that’s the part I still don’t understand about this)

    Once I also stubbed the valueForKey method on my mock objects, and then worked through an OCMock bug (or limitation?) documented here, I was able to get my tests working,

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

Sidebar

Related Questions

I have an application that uses Core Data that has a relationship that I
I have a Core Data based mac application that is working perfectly well until
I have a core data application which uses a navigation controller to drill down
I have a Core Data based application that stores hierarchal data displayed using a
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have an application that will use Core Data. I've added the Core Data
I have a non document-based Core Data application. There's an NSTreeController that manages a
I am writing a Mac app that uses Core Data as its persistence layer,
I have a an application that uses CoreData. One of the entities contains date
I have an application that uses a UITableView to present data that I have

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.