Re: Data Source {key value coding-compliant} problem...
Re: Data Source {key value coding-compliant} problem...
- Subject: Re: Data Source {key value coding-compliant} problem...
- From: Dustin Voss <email@hidden>
- Date: Sat, 29 May 2004 14:40:49 -0700
On 29 May, 2004, at 10:56 AM, Frederick C. Lee wrote:
I'm trying to create a NSMutableArray of cities & routing codes by
loading a simple data model called 'cityTest' that essentially has only
NSString instance variables. I load the cityTest object into an array
(cityData) to be the DataSource of a Table View (NSTableView).
...
cityData = [NSMutableArray array];
int theCount = [cityKeys count];
for(index = 0; index < theCount; index++) {
cityTest *myCity = [[cityTest alloc] init];
[myCity setCityName: [cityKeys objectAtIndex:index]];
[myCity setRoutingCode: [cityMArray objectAtIndex:index]];
[cityData addObject:myCity];
[myCity release];
}
...
@interface cityTest : NSObject {
NSString *cityName, *routingCode;
NSAttributedString *aMemo;
}
What I always get is the following:
2004-05-29 10:44:40.143 docCountries[3265] [<cityTest 0x371a80>
valueForUndefinedKey:]: this class is not key value coding-compliant
for the key City.
*** malloc[3265]: Deallocation of a pointer not malloced: 0xbfffd190;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
-----
I read that NSObject is key-value coding compliant and hence, my
cityTest model object is ALSO compliant. Yet I get the error message;
even when I load the data with just simple one-column NSStrings {i.e.,
cityData = [cityKeys copy]}, I get the SAME error.
Okay, there are a couple of problems here.
First, the "not key value coding-compliant for the key City" error
means that somewhere, you are trying to access the "City" key. But your
cityTest class does not have a "City" key. It can only automatically
offer the "cityName", "routingCode", and "aMemo" keys.
Second, you call the -setCityName: and -setRoutingCode: methods on
myCity. Unless you actually wrote these methods, they won't exist.
NSObject sure doesn't implement them. You probably got a compiler
warning. What NSObject *does* implement the -valueForKey: and
-setValue:forKey: methods. These are the methods through which key
values are accessed.
-valueForKey: and -setValueForKey: will call (e.g.) -setCityName: if
you implement it, but they won't implement it for you. You can replace
the calls to -setCityName: and -setRoutingCode: with calls to
-setValue:forKey:, using the keys "cityName" and "routingCode".
Third, don't name the class "cityTest"; it's too easy to confuse with a
variable. Name it "CityTest".
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.