Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuteFetchRequest intermittently throwing exception with same parameters. "not key value coding-compliant for the key"
    primarykey
    data
    text
    <p><strong>EDIT</strong> Thanks to Matt's post I now understand that I should not be trying to access 'started' as an array. However, if that is the case, I would like to know why this code appears to be working in other places. It still seems to me that this should be "one-or-the-other." It should work or it shouldn't.</p> <p><strong>ORIGINAL</strong> I'm using the same fetch request in various parts of my code to find the most recent game:</p> <pre><code>Game *lastGame = [[[CoreDataAccess managedObjectContext] fetchObjectsForEntityName:@"Game" withPredicate:@"started == started.@max"] anyObject]; </code></pre> <p>'Game' is an NSManagedObject and 'started' is a date attribute. 'started' is set exactly once per object in awakeFromInsert. It is never changed after that. Game is never directly instantiated, but it has three subclasses. I have tried making Game both abstract and concrete, but neither has any effect on this problem.</p> <p>I'm using an NSManagedObjectContext category to perform the fetch, as shown on cocoa with love here <a href="http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html" rel="nofollow noreferrer">http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html</a>. </p> <p>The error I am getting is the following:</p> <pre><code>Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. [&lt;__NSDate 0xebb1130&gt; valueForUndefinedKey:]: this class is not key value coding-compliant for the key @max. with userInfo { NSTargetObjectUserInfoKey = "2010-11-06 11:16:53 GMT"; NSUnknownUserInfoKey = "@max"; } </code></pre> <p>It looks to me like the predicate might be trying to apply @max to a single NSDate, instead of all 'started' attributes in all games. I'm not sure though. I'm not very good with predicates, and it took me a lot of trial and error to make this one. I don't understand how the exact same fetch can have errors in different places, though.</p> <p>The fetch is not part of an NSFetchedResultsController, but I am using a fetchedResultsController in the class where I'm getting the error. For example:</p> <pre><code>- (void)configureCell:(UITableViewCell*)cell atIndexPath:(NSIndexPath*)indexPath{ Game *game = [self.frc objectAtIndexPath:indexPath]; Game *lastGame = [[[CoreDataAccess managedObjectContext] fetchObjectsForEntityName:@"Game" withPredicate:@"started == started.@max"] anyObject]; // Sometimes we get past this line, sometimes we don't... NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"EEE, MMM d, yyyy h:mm a"]; if (game != lastGame) cell.detailTextLabel.text = [format stringFromDate:game.started]; else cell.detailTextLabel.text = @"In Progress"; [format release]; ... } </code></pre> <p>and also here:</p> <pre><code>- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. Game *lastGame = [[[CoreDataAccess managedObjectContext] fetchObjectsForEntityName:@"Game" withPredicate:@"started == started.@max"] anyObject]; if (lastGame == [frc objectAtIndexPath:indexPath]) return NO; return YES; } </code></pre> <p>This exact fetch is performed several times in several places, for example on startup, but it only crashes in one class. As I said it is intermittent, but it seems to be sometime after I create a new Game object. The game is created in one tab, and the code above is from a second tab which shows history.</p> <p>I have seen a similar error <a href="https://stackoverflow.com/questions/3428323/entity-is-not-key-value-coding-compliant-for-the-key-objective-c-cocoatouch-cor">here</a>. In that case the problem was solved by restarting the computer, which finally allowed XCode to realize that the attribute had been deleted from the model. I have tried that, and I'm still experiencing the problem. I have also tried deleting and recreating the 'started' attribute in the model. I have also read the Core Data Troubleshooting Guide, but was unable to find any help there either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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