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

  • Home
  • SEARCH
  • 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 8139203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:44:51+00:00 2026-06-06T11:44:51+00:00

I have a subclass of the CoreDataTableViewController (subclass of UITAbleViewController dome by the people

  • 0

I have a subclass of the CoreDataTableViewController (subclass of UITAbleViewController dome by the people on Stanford done to link CoreData and TableViews). On this Class, I want to perform a fecth, sorting by an attribute called “definition” and the code which executes it is the following:

- (void)setupFetchedResultsController{


    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:self.entity];

    request.propertiesToFetch=[NSArray arrayWithObject:@"definition"];
    request.returnsDistinctResults=YES;

    NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"%K != nil", @"definition"]; 
    NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"%K != ''", @"definition"];
    NSPredicate *predicate3=  [NSPredicate predicateWithFormat:@"%K contains[cd] %@", @"definition", self.seachBar.text];

    NSArray *prepredicateArray;

    if ([self.seachBar.text length]) {
         prepredicateArray = [NSArray arrayWithObjects:predicate1, predicate2, predicate3,nil];

    }else {
         prepredicateArray = [NSArray arrayWithObjects:predicate1, predicate2,nil];

    }

    request.predicate=[NSCompoundPredicate andPredicateWithSubpredicates:prepredicateArray];
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"definition" ascending:YES ]];





    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.managedObjectContext
                                                                          sectionNameKeyPath:nil
                                                                                   cacheName:nil];




    [self performFetch];


}

If I understood it correctly, setting request.returnsDistinctResults=YES; should avoid fetching duplicates. However it doesn’t work and I’m seeing duplicates of this attribute’s value.

Is there something I’m missing there? I’d appreciate some pointings there. Thank you in advance.

EDIT: If anyone is having the same issue here, after applying David’s answer the resulting fetchedResultsController is just a NSDIctionary with object with only the requested value, which for displaying only purposes is quite fine. One thing I’ve done in cellForRowAtIndexPath in order to display the results on the cell label is:

Before:

HNMR *hnmr = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text=hnmr.definition;

After:

cell.textLabel.text=[[self.fetchedResultsController objectAtIndexPath:indexPath] valueForKey:@"definition"];
  • 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-06T11:44:52+00:00Added an answer on June 6, 2026 at 11:44 am

    From the documentation of returnsDistinctResults:

    This value is only used if a value has been set for propertiesToFetch.

    From the documentation of propertiesToFetch:

    This value is only used if resultType is set to NSDictionaryResultType.

    From the documentation of resultType:

    The default value is NSManagedObjectResultType.


    This all tells me that the propertiesToFetch is ignored because you haven’t set the resultType yourself and the default it to return managed objects instead of dictionaries. Since the propertiesToFetch is ignored the returnsDistinctResults is ignored as well and thus you are still getting duplicates.

    Try setting the result type to return dictionaries instead of managed objects.

    request.resultType = NSDictionaryResultType;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI All. I have subclass of UIScrollView. IN this class I have added some
I have subclass UIView class in a Bounce class with Accelerometer. This Bounce class
I have a subclass and I want it to not include a class attribute
I have a subclass of an ArrayAdapter declared like this public class ShoppingCartAdapter extends
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a subclass of QTableWidget with the following code: connect(this, SIGNAL(cellChanged(int, int)), this,
I have a subclass of JPanel , and I want it to, as soon
I have a subclass from control and I want set text for that. When
I have a subclass of NSWindowController that has its own nib and another class
I have a subclass of QGraphicsRectItem. The mouseMoveEvent handler looks like this: void BTNodeGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent*

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.