Tag: Core Data

Object is not key value coding compliant

Lately I have been playing around with Objective-C development on mac. As I was working through a tutorial I kept getting the following error for a calculated read-only property.

[<NSManagedObject 0x2000c3c20> valueForUndefinedKey:]: the entity Expense is not key value coding-compliant for the key "filename".

Below is the definition of the class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// Expense.h
#import <Cocoa/Cocoa.h>
@interface Expense : NSManagedObject {}
@property (readonly) NSString* filename;
@end


// Expense.m
#import "Expense.h"
@implementation Expense
- (NSString *) filename {
	return @"TestingPath";
}
@end

The class definition is OK so the error didn’t make sense. After some troubleshooting I found out what was causing this. Since this was my first application I didn’t know that I had to tell the model what class it should be using, and, unfortunately, the book that I was using didn’t mention it either (or maybe I missed it).

Anyways, if you get this error then make sure that you have associated the class with the model. To do this you have to specify the class name under “Class” in the model definition (see screenshot below).

Make sure to specify the class in the model (highlighted field)