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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:42:10+00:00 2026-06-14T03:42:10+00:00

I came up with a solution to this using subquery, but I don’t understand

  • 0

I came up with a solution to this using subquery, but I don’t understand why what I was trying to do first didn’t work.

Here’s my data model. I’m fetching on Advice.

enter image description here

I can do the following as a predicate:

[NSPredicate predicateWithFormat:@"ANY conditions.terrain == %@", aTerrainObject];

that works fine, and returns any piece of advice where at least one of its conditions has that terrain type.

However, when I try to do this, it fails:

[NSPredicate predicateWithFormat:@"ANY conditions.terrain == nil"];

What I want to do is return any piece of advice where at least one of its conditions doesn’t have a terrain type set.

However, the following does work:

[NSPredicate predicateWithFormat:@"SUBQUERY(conditions, $x, $x.terrain == nil).@count > 0"];

Can anyone explain why, when searching for nil, I can’t use the ANY syntax?

  • 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-14T03:42:11+00:00Added an answer on June 14, 2026 at 3:42 am

    Can anyone explain why, when searching for nil, I can’t use the ANY syntax?

    Yep! Here’s what’s going on.

    [NSPredicate predicateWithFormat:@"ANY conditions.terrain == nil"];
    

    First, let’s break this up into the appropriate left and right expressions:

    conditions.terrain
    

    This will be evaluated by taking the SELF object (an Advice instance) and requesting the valueForKeyPath:@"conditions.terrain". The result of this keypath will be a collection. You’re essentially doing:

    Advice *a = ...;
    NSSet *conditions = [a conditions];
    NSSet *terrains = [conditions valueForKey:@"terrain"];
    

    So, you have a collection of (potential) Terrain instances. Now, what do we know about collections in Objective-C? Well for one thing, they cannot contain nil. They can only contain objects. This means that when it executes the ANY portion of the predicate, it’s going to iterate through the items in the array and see that none of them are nil.

    Thus, your predicate is failing. I tried playing around with some other variations (using [NSNull null] instead of nil, etc), but none of them seemed to work.

    It would therefore appear that your use of a SUBQUERY to solve this is about as good as you could get. I would highly recommend filing a bug detailing your expectations and expressing why you think this should work.

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

Sidebar

Related Questions

I came across this thread when I was looking for a solution, but it
I came with below solution but I believe that must be nicer one out
(Came up with this question in the course of trying to answer this other
I am trying to separate behaviour from data completely in my classes and came
After looking through Paypal docs for a solution for this circumstance, I came up
I have came with solution to remove duplicates from generic list<T> in .NET 2.0
So basically I came up with a semi home grown solution to lazy loading
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
Came across something like this today, and was wondering if there was an equivalent
Came across a problem whereby I wanted the last time data was imported to

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.