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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:24:25+00:00 2026-05-14T08:24:25+00:00

I have a core data based app that manages a bunch of entities. I’m

  • 0

I have a core data based app that manages a bunch of entities. I’m looking to be able to do the following.

I have an entity “SomeEntity” with the attributes: name, type, rank, foo1, foo2.

Now, SomeEntity has several rows if we’re speaking strictly in SQL terms. What I’m trying to accomplish is to retrieve only available types, even though each instance can have duplicate types. I also need them returned in order according to rank. So in SQL, what I’m looking for is the following:

SELECT DISTINCT(type) ORDER BY rank ASC

Here is the code I have so far that’s breaking:

NSError *error = NULL;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:@"type", @"rank", nil]];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeEntity" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

// sort by rank
NSSortDescriptor *rankDescriptor = [[NSSortDescriptor alloc] initWithKey:@"rank" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:rankDescriptor,nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[rankDescriptor release];

NSArray *fetchResults = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

[fetchRequest release];

return fetchResults;

Right now that is crashing with the following: Invalid keypath section passed to setPropertiesToFetch:

  • 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-14T08:24:25+00:00Added an answer on May 14, 2026 at 8:24 am
    NSManagedObjectContext * ctx ; /* some ctx */    
    NSFetchRequest * req; /* your request */
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeEntity" inManagedObjectContext:context];
    NSDictionary *entityProperties = [entity propertiesByName];
    [req setEntity:entity];
    [req setReturnsDistinctResults:YES];
    [req setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"type"]]];
    [req setSortDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"rank" ascending:YES]]];
    NSArray * result = [ctx executeFetchRequest:req error:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document-based Core Data app. My main Core Data entity has several
I have a non document-based Core Data application. There's an NSTreeController that manages a
I have a core data based app I am working on, that uses an
I have a navigation based app that uses Core Data for storage. The schema
I have a Core Data based mac application that is working perfectly well until
I have Core Data setup in my app and need to fetch a bunch
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have an app that uses core data. The app is free for download
I've got a document based App using Core Data, and have a tableView which
I have a Document based core data app. The main document window has a

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.