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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:16:53+00:00 2026-06-16T22:16:53+00:00

I’m using NSFetchedResultsController (NSFRC) to display information in a UITableView . I’m trying to

  • 0

I’m using NSFetchedResultsController (NSFRC) to display information in a UITableView. I’m trying to create the option for the user to sort the cells in sections as opposed to alphabetically. The problem is, the sections would then be determined using downloaded information. On top of this the section for each item will be changing relatively often so I don’t want to save the section. I have noticed the mention of transient attributes, in my research of similar problems, but i’ve never used these before I’m not sure if I can use them baring in mind that all the calculations are done once the data has already been loaded, and I also want this solution to be compatible with my previous Core Data database. Also I’m not particularly great at Core Data, (nor Objective-C at that!) so I’m not entirely sure how I’d go about doing this.

So here’s what I want to go for if we’re using transient attributes (this next bit is theoretical as I don’t know if transient attributes are the correct way forward). I would like 4 possible sections, 0-3 (I’ll rename them using the TableView delegate to get around sorting problems). When the calculations are done, each cell will be assigned the transient attribute (if needed, the default section would be 2). I hope this all makes sense.

Right, now for some theoretical code. First I create the transient property in the Data Model screen-thing, and make it transient by checking the transient check box… Sounds simple enough.

In the code for the calculations in willDisplayCell (needs to be done in wDC for a couple of reasons), the entity could be saved like this:

MyEntity *myEntity = [self.fetchedResultsController objectAtIndexPath:indexPath];

myEntity.sectionTransientProperty = 2;

if (![self.managedObjectContext save:&error]) {
    NSLog(@"Error: %@", error);
    FATAL_CORE_DATA_ERROR(error);
    return;
}  

Done, right? Is that how we assign a value to a transient property?

Then I change the sorting option in NSFRC when I alloc it:

fetchedResultsController = [[NSFetchedResultsController alloc]
                                initWithFetchRequest:fetchRequest
                                managedObjectContext:self.managedObjectContext
                                sectionNameKeyPath:@"sectionTransientProperty"
                                cacheName:@"MyEntity"];

How are we doing, what else do I need to do? Or have I got this so horribly wrong I should just give up on Core Data and NSFRC? If you guys could help guide me through this I’d really appreciate it. If you need me to post any more code I would be happy to.

Regards,
Mike

  • 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-16T22:16:54+00:00Added an answer on June 16, 2026 at 10:16 pm

    If you want an FRC with sections, you have to add a sort descriptor to the fetch request, and that sort descriptor cannot be based on transient attributes.

    See the documentation of initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:`:

    If the controller generates sections, the first sort descriptor in
    the array is used to group the objects into sections; its key must
    either be the same as sectionNameKeyPath or the relative ordering
    using its key must match that using sectionNameKeyPath.

    and Fetch Predicates and Sort Descriptors in the “Core Data Programming Guide”:

    The SQL store, on the other hand, compiles the predicate and sort
    descriptors to SQL and evaluates the result in the database itself.
    This is done primarily for performance, but it means that evaluation
    happens in a non-Cocoa environment, and so sort descriptors (or
    predicates) that rely on Cocoa cannot work. The supported sort
    selectors are …
    In addition you cannot sort on transient properties using the SQLite store.

    This means that you cannot create sections purely on transient attributes. You need a persistent attribute that creates the ordering for the sections.

    UPDATE: A typical use of a transient attribute as sectionNameKeyPath is: Your objects have a “timeStamp” attribute, and you want to group the objects into sections with one section per month (see the DateSectionTitles sample code from the iOS Developer Library). In this case you have

    • a persistent attribute “timeStamp”,
    • use “timeStamp” as first sort descriptor for the fetch request,
    • a transient attribute “sectionIdentifier” which is used as sectionNameKeyPath. “sectionIdentifier” is calculated from “timeStamp” and returns a string representing the year and the month of the timestamp, e.g. “2013-01”.

    The first thing the FRC does is to sort all fetched objects according to the “timeStamp” attribute. Then the objects are grouped into sections according to the “sectionIdentifier” attribute.

    So for a FRC to group the objects into sections you really need a persistent attribute. The easiest solution would be to add a persistent attribute “sectionNumber” to your entity, and use that for “sectionNameKeyPath” and for the first sort descriptor.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
i want to parse a xhtml file and display in UITableView. what is the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

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.