I am new to core data I would appreciate some assistance in the code below that I need to display the number of attributes in an entity;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
//NSUInteger attributeCount = [[[object entity] attributesByName] count];
float valueSF = 0;
for (NSManagedObject *object in [sectionInfo objects]) {
NSUInteger attributeCount = [[[object entity] attributesByName] count];
valueSF += [[object valueForKey:@"value"] floatValue];
valueSF = valueSF / attributeCount;
}
return [NSString stringWithFormat:@"[Average = %.03f] [Cases = %i]", valueSF, [[sectionInfo objects] count]];
}
Core Data provides good introspection. Assuming you mean the number of attributes actually declared for the entity in the data model, you’d want:
If you want to include the number of relationships, replace
attributesByNamewithpropertiesByName.