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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:25:18+00:00 2026-05-18T10:25:18+00:00

I have an array of objects that I’d like to filter using a predicate,

  • 0

I have an array of objects that I’d like to filter using a predicate, but I’ve not been able to figure out the syntax (or whether it’s impossible).

Let’s say the object is location and it has properties of latitude and longitude. I’ve got an array of these called allLocations and I want to produce a new array of locations where the latitude property is greater than 30.

When fetching managed objects you can simply use the property name, but not so with arrays:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"latitude > 30.0"];

returns no matches (despite there being plenty of location objects with latitudes > 30.0.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.latitude > 30.0"];

is no good either, while

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"[SELF latitude] > 30.0"];

and

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"[location latitude] > 30.0"];

throw exceptions.

Am I out of luck?

  • 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-18T10:25:18+00:00Added an answer on May 18, 2026 at 10:25 am

    What you’re looking for is the filteredArrayUsingPredicate: method of NSArray. Your first predicate attempt above will work fine when you pass it to that method.

    It’s worth noting that NSMutableArray uses a different method to achieve a similar effect, filterUsingPredicate:. The MutableArray version alters the receiver, whereas the Array version returns a new Array.

    Reference:
    NSArray Class Reference
    NSMutableArray Class Reference

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

Sidebar

Related Questions

I have a vector-like class that contains an array of objects of type T
I have an array of objects that are positioned using CGPoints . At certain
I have an Array of Objects that need the duplicates removed/filtered. I was going
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have an array of objects that I need to sort by a position
I have an array of objects that have QTTime structs as attributes. The objects
I have an array of objects that have 2 properties: Key and Value. I
I have an array of objects that I'm trying to add to the Items
I have a array of objects that selected from core data. I need select

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.