I’m having a problem with relationships between to entities in Core Data. I’m parsing some JSON and adding the entities:
if ([hourSets isKindOfClass:[NSArray class]]) { // check to see that we have got some hours back
for (NSDictionary *hourSet in hourSets) {
Hourset *thisHourSet = (Hourset *)[NSEntityDescription
insertNewObjectForEntityForName:@"Hourset"
inManagedObjectContext:managedObjectContext];
[thisHourSet setStartDate:[hourSet objectForKey:@"start_date"]];
[thisHourSet setEndDate:[hourSet objectForKey:@"end_date"]];
[record addHoursetsObject:thisHourSet];
}
}
…and then later trying to grab them again:
NSSet *hourSets = [self.listing valueForKeyPath:@"hoursets.hourset"];
NSLog(@"There are %@ hourSets", [hourSets count]);
I’m getting Program received signal: “EXC_BAD_ACCESS”. when trying to access that hourSets NSSet in any way, including just counting the items in it.
Any suggestions? Pretty stumped. Thanks!
I am inferring your entity graph here but:
… translates to a keypath of
listing.hoursets.hoursetwhich does not appear to return a set. Both the first and last elements are singular and therefore by convention not sets.I would suggest logging the class of the return to confirm what, if anything, you’re getting back.
Update:
(Forehead slap) The problem is actually the log statement itself. It should be:
… because
countreturns an NSUInteger.