I had a problem when my application crashes with the following exception:
ABC [1936: c07] * Application terminated due to an unmapped exception "NSUnknownKeyException", reason: '[<_NSObjectID_48_0 0xb63e310> valueForUndefinedKey:]: this class is not a key value compatible with the code for the key identifier.'
A strange problem with this exception is that this does not happen when using iOS5. See Code in which an exception occurs below:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ((self.sectionInfoArray == nil) || ([self.sectionInfoArray count] != [self numberOfSectionsInTableView:self.tableView])) { NSMutableArray *infoArray = [[NSMutableArray alloc] init]; for (Tour *tour in self.tours) { SectionInfo *sectionInfo = [[SectionInfo alloc] init]; sectionInfo.tour = tour; sectionInfo.open = NO; NSLog(@"Tour Details Count %@", [[tour tourDetails] objectAtIndex:0]); NSNumber *defaultRowHeight = [NSNumber numberWithInteger:DEFAULT_ROW_HEIGHT]; NSInteger countOfQuotations = [[sectionInfo.tour tourDetails] count]; for (NSInteger i = 0; i < countOfQuotations; i++) { [sectionInfo insertObject:defaultRowHeight inRowHeightsAtIndex:i]; } [infoArray addObject:sectionInfo]; } self.sectionInfoArray = infoArray; }
}
Whether this exception was raised because I got the Fetched property defined in the Tour class, which receives an array of TourDetail classes. See the implementation code for both classes below:
Any help in this matter would be greatly appreciated. Since I do not understand how I can fix this.
Thanks Michael
UPDATE:
When I remove the Fetched property, an exception does not occur with iOS6. See the predicate that I configured below:
Selected property tourDetails Predicate tour_id == $ FETCH_SOURCE.id
Do you see something that I am doing wrong with setting up this predicate? My goal is to use this so that I can return an array of TourDetail objects for each tour_id that computes the id column inside the Tour table.
UPDATE:
I was able to diagnose that the exception is thrown due to the Predicate, because when I call both tables separately, the exception does not occur. Can you see any problems with the predicate that I created?
Refer to the code below showing how I retrieve objects from the underlying DB:
- (void)viewDidLoad { [super viewDidLoad]; [DrivingToursContent setupStaticData]; self.tableView.sectionHeaderHeight = HEADER_HEIGHT; _openSectionIndex = NSNotFound; self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"custombackground.ptoung"]]; self.managedObjectContext = [[BaseCoreDataController sharedInstance] newManagedObjectContext]; [self loadRecordsFromCoreData]; [self loadRecordsFromCoreDataForTourDetail]; NSLog(@"Tour Detail array count: %d", [self.toursTest count]); // Do any additional setup after loading the view. } - (void)loadRecordsFromCoreData { [self.managedObjectContext performBlockAndWait:^{ [self.managedObjectContext reset]; NSError *error = nil; NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:NSStringFromClass([Tour class])]; [request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES]]]; self.tours = [self.managedObjectContext executeFetchRequest:request error:&error]; }]; }
UPDATE:
The root of the problem definitely comes from the Predicate that I defined for the Fetched property, but can you tell me how I should write the predicate to link between the two tables. Like when I write the predicate tour_id == 0 and directly refer to the identifier that, as I know, exists, the corrected property works correctly. But when I use $ FETCH_SOURCE.id, a key value encoding exception is thrown. What property do you use to refer to the table to which you want to bind?
In fact, appreciate all your help.
Thanks Michael