Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're asking core data to fetch based on a lazily loaded attribute. I dont think this is going to work. You either need to set your seasonNameVisible when you set the season name or, which may make more sense, separate out the storage of your season name into whatever is the prefix (that you are removing to give the visible name) and whatever is the real name. </p> <p>After the additional information in the comments, I would advise the following:</p> <ul> <li>split your season into two attributes, a season number (int) and season name</li> <li>sort your fetch request on season number</li> <li>section name key path is a new read-only property on your object, which returns a string made of the number and name</li> </ul> <p>The error you are seeing in your comment is normal when altering a fetch request used with an FRC. Delete the app from the simulator and re-build and it will go away, or use a nil cache while developing. The FRC stores its cache permanently (eg between runs) so any changes upset it. </p> <p>Section name key path can be any key path or property name you like, as long as the sorting is the same. From the docs for NSFetchedResultsController:</p> <blockquote> <p><em>sectionNameKeyPath</em></p> <p>A key path on result objects that returns the section name. Pass nil to indicate that the controller should generate a single section. The section name is used to pre-compute the section information. If this key path is not the same as that specified by the first sort descriptor in fetchRequest, they must generate the same relative orderings. For example, the first sort descriptor in fetchRequest might specify the key for a persistent property; <strong>sectionNameKeyPath might specify a key for a transient property derived from the persistent property</strong>.</p> </blockquote> <p>So, you'd have a <code>Season</code> object with two persistent attributes, <code>seasonNumber</code> and <code>seasonName</code>. You'd sort your fetch request by season number. Your section name key path (for a fetch presumably on episodes, which have a <code>season</code> relationship) would be <code>@"season.seasonSectionName"</code>, implemented as follows - no changes in your managed object model, just changes to your Season object:</p> <p>Season.h:</p> <pre><code>@property(nonatomic,readonly) NSString *seasonSectionName; </code></pre> <p>Season.m:</p> <pre><code>-(NSString*)seasonSectionName { return [NSString stringWithFormat:@"%d - %@",self.seasonNumber,self.seasonName]; } </code></pre> <p>All you're really doing is decorating the season number with another property. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload