views:

104

answers:

2

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

--- EDIT ---

OK so after digging around more I think this is a CoreData misunderstanding on my part.

The API includes the classes DicomSeries and DicomStudy which are subclasses of NSManagedObject and are included in the xcdatamodel file.

I am including the xcdatamodel file as a "compiled source" and DicomSeries.h and DicomStudy.h

DicomSeries and DicomStudy are "hard-coded" with:

- (NSString*) type
{
    return @"Series";
}

But the objects I create for itemStudy Never call this method. Objects created like itemStudy above, do. Even DicomSeries objects called within the main program do. But not ones that I make with the fetch request from the same database.

Even if I do:

DicomSeries *itemSeries = [_context executeFetchRequest:request]

Where the request has entity @"Series" which is of Class DicomSeries so it SHOULD respond to:

[itemSeries valueForKey:@"type"];

but it doesn't.

I feel like there's a big giant gap of CoreData I'm missing. My NSManagedObjectModel that I'm using in my persistent Store Coordinator and my context has Entities for Series and is of managedObjectClassName DicomSeries so...

yeah.

lol, wut?

+1  A: 

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?

This might be because the Class of item implements KVC compliant the property "type" while the Entity of client does not have this property. The property list only returns the Core Data Entity defined properties

Take a look at

unsigned int total_method_count = 0;
Method * method_list = class_copyMethodList(object_getClass([self class]), &total_method_count);
@try
{
    int method_counter = 0;
    for (method_counter = 0; method_counter < total_method_count; method_counter++)
    {
        Method method = method_list[method_counter];
        // check if method the KVC getter you are interested in

    }
}
Martin Brugger
This is good, but it gives me stuff like _retain_1 which look more like NSObject Methods than anything the object has. Nothing for `@"type"`
Stephen Furlani
A: 

The answer to this question was actually solved by solving my other question, here.

Thanks for the help.

Stephen Furlani