Mystery Key Value Coding Key
Posted
by Stephen Furlani
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Furlani
Published on 2010-05-27T20:03:09Z
Indexed on
2010/05/28
9:51 UTC
Read the original article
Hit count: 457
Hello,
I'm attempting to load data from an undocumented API (OsiriX).
Getting the NSManagedObject like this:
NSManagedObject *itemStudy = [[BrowserController databaseOutline] itemAtRow: [[BrowserController databaseOutline] selectedRow]];
works just fine.
But getting the NSManagedObject like this:
seriesArray = [_context executeFetchRequest:request error:&error];
NSManagedObject *itemSeries = [seriesArray objectAtIndex:0];
Generates an error when I call [itemSeries valueForKey:@"type"]
2010-05-27 11:04:48.178 rcOsirix[27712:7b03] Exception: [<NSManagedObject 0xd30fd0> valueForUndefinedKey:]: the entity Series is not key value coding-compliant for the key "type".
This confuses me thoroughly. If I print the KVC values for itemSeries I get this list:
2010-05-27 11:04:48.167 rcOsirix[27712:7b03] KVC comment
2010-05-27 11:04:48.168 rcOsirix[27712:7b03] KVC date
2010-05-27 11:04:48.168 rcOsirix[27712:7b03] KVC dateAdded
2010-05-27 11:04:48.169 rcOsirix[27712:7b03] KVC dateOpened
2010-05-27 11:04:48.169 rcOsirix[27712:7b03] KVC displayStyle
2010-05-27 11:04:48.170 rcOsirix[27712:7b03] KVC id
2010-05-27 11:04:48.170 rcOsirix[27712:7b03] KVC modality
2010-05-27 11:04:48.170 rcOsirix[27712:7b03] KVC name
2010-05-27 11:04:48.171 rcOsirix[27712:7b03] KVC numberOfImages
2010-05-27 11:04:48.171 rcOsirix[27712:7b03] KVC numberOfKeyImages
2010-05-27 11:04:48.171 rcOsirix[27712:7b03] KVC rotationAngle
2010-05-27 11:04:48.172 rcOsirix[27712:7b03] KVC scale
2010-05-27 11:04:48.172 rcOsirix[27712:7b03] KVC seriesDICOMUID
2010-05-27 11:04:48.173 rcOsirix[27712:7b03] KVC seriesDescription
2010-05-27 11:04:48.173 rcOsirix[27712:7b03] KVC seriesInstanceUID
2010-05-27 11:04:48.173 rcOsirix[27712:7b03] KVC seriesSOPClassUID
2010-05-27 11:04:48.174 rcOsirix[27712:7b03] KVC stateText
2010-05-27 11:04:48.174 rcOsirix[27712:7b03] KVC thumbnail
2010-05-27 11:04:48.174 rcOsirix[27712:7b03] KVC windowLevel
2010-05-27 11:04:48.175 rcOsirix[27712:7b03] KVC windowWidth
2010-05-27 11:04:48.175 rcOsirix[27712:7b03] KVC xFlipped
2010-05-27 11:04:48.176 rcOsirix[27712:7b03] KVC xOffset
2010-05-27 11:04:48.176 rcOsirix[27712:7b03] KVC yFlipped
2010-05-27 11:04:48.176 rcOsirix[27712:7b03] KVC yOffset
2010-05-27 11:04:48.177 rcOsirix[27712:7b03] KVC mountedVolume
2010-05-27 11:04:48.177 rcOsirix[27712:7b03] KVC study
2010-05-27 11:04:48.178 rcOsirix[27712:7b03] KVC images
The KVC for itemStudy is this:
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC accessionNumber
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC comment
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC date
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC dateAdded
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC dateOfBirth
2010-05-27 10:46:40.336 OsiriX[27266:a0f] KVC dateOpened
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC dictateURL
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC expanded
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC hasDICOM
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC id
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC institutionName
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC lockedStudy
2010-05-27 10:46:40.337 OsiriX[27266:a0f] KVC modality
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC name
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC numberOfImages
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC patientID
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC patientSex
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC patientUID
2010-05-27 10:46:40.338 OsiriX[27266:a0f] KVC performingPhysician
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC referringPhysician
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC reportURL
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC stateText
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC studyInstanceUID
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC studyName
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC windowsState
2010-05-27 10:46:40.339 OsiriX[27266:a0f] KVC albums
2010-05-27 10:46:40.340 OsiriX[27266:a0f] KVC series
If I use code:
NSDictionary *props = [[item entity] propertiesByName];
for (NSString *s in [props allKeys]) {
NSLog(@"KVC %@", s);
}
Yet itemStudy
throws no error if I call [itemStudy valueForKey:@"type"]
when it should because there's no KVC for @"type"
!!!
Granted, the objects are different but neither of them contain the key @"type"
and they both should throw errors, yet the Osirix code Tests for both conditions:
if ([[item valueForKey:@"type"] isEqualToString:@"Series"]) {
...
}
if ([[item valueForKey:@"type"] isEqualToString:@"Study"]) {
...
}
And throws no errors. Yet when I load an NSManagedObject
of the same exact model and entity @"Series"
it throws the 'no key value' when passed into the conditions above.
Am I missing something? Both the superentity
and subentities
of itemSeries and itemStudy are nil
so they don't inherit from something that has KVC @"type"
.
I'm totally at a loss as to explain what is going on.
--- EDIT ---
I know no one can explain what is going on... but maybe where to start looking? How would itemStudy have the extra KVC @"type" that doesn't show up in it's property list?
Thank you for your assistance,
-Stephen
© Stack Overflow or respective owner