神秘键值编码键 [英] Mystery Key Value Coding Key
问题描述
我正在尝试从未记录的API(OsiriX)加载数据。
获取NSManagedObject如下:
NSManagedObject * itemStudy = [[BrowserController databaseOutline] itemAtRow:[[BrowserController databaseOutline] selectedRow]];
工作得很好。
但是得到NSManagedObject这样:
seriesArray = [_context executeFetchRequest:request error:& error];
NSManagedObject * itemSeries = [seriesArray objectAtIndex:0];
当我调用 itemSeries valueForKey:@type]
2010-05-27 11:04:48.178 rcOsirix [27712:异常:[< NSManagedObject 0xd30fd0> valueForUndefinedKey:]:实体系列不是键值编码符合键类型。
如果我打印itemSeries的KVC值,我得到这个列表:
2010-05-27 11:04:48.167 rcOsirix [27712 :7b03] KVC评论
2010-05-27 11:04:48.168 rcOsirix [27712:7b03] KVC日期
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模态
2010-05-27 11:04: 48.170 rcOsirix [27712:7b03] KVC名称
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系列DICOMUID
2010-05-27 11:04:48.173 rcOsirix [27712:7b03] KVC系列描述
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 installedVolume
2010-05-27 11:04:48.177 rcOsirix [27712 :7b03] KVC study
2010-05-27 11:04:48.178 rcOsirix [27712:7b03] KVC图片
itemStudy的KVC为:
2010-05-27 10:46:40.336 OsiriX [27266 :a0f] KVC accessionNumber
2010-05-27 10:46:40.336 OsiriX [27266:a0f] KVC评论
2010-05-27 10:46:40.336 OsiriX [27266:a0f] KVC date
2010-05-27 10:46:40.336 OsiriX [27266:a0f] KVC添加日期
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模态
2010-05-27 10:46:40.338 OsiriX [27266:a0f] KVC名称
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 performPhysician
2010-05-27 10:46:40.339 OsiriX [27266:a0f] KVC referPhysician
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专辑
2010-05-27 10:46:40.340 OsiriX [27266:a0f] KVC系列
b $ b
如果我使用代码:
NSDictionary * props = [[item entity] propertiesByName];
(NSString * s in [props allKeys]){
NSLog(@KVC%@,s);
}
然而 itemStudy
没有错误,如果我调用 [itemStudy valueForKey:@type]
时应该是因为没有KVC为 @type
!!!
授予,对象不同,但它们都不包含键 @ type
错误,但Osirix代码测试这两个条件:
if([[value value]:isEqualToString: Series]){
...
}
if([[item valueForKey:@type] isEqualToString:@Study]){
...
}
并没有错误。但是当我加载相同确切模型和实体 @Series
的 NSManagedObject
时,它会抛出no key value
我错过了什么? itemSeries和itemStudy的 superentity
和子实体
都是 nil
所以它们不继承自具有KVC @type
的东西。
我知道没有人可以解释发生了什么...但也许在哪里开始寻找?
感谢您的帮助,
$ b $ b-Stephen
--- EDIT ---
该API包括类 DicomSeries
和 DicomStudy
这是NSManagedObject的子类,并包含在xcdatamodel文件中。
我将xcdatamodel文件包含为编译源和DicomSeries.h和DicomStudy.h
DicomSeries
和 DicomStudy
是硬编码的:
- (NSString *)type
{
return @Series;
}
但是我创建的对象 itemStudy
不要调用此方法。对象创建像 itemStudy
上面,做。甚至 DicomSeries
在主程序中调用的对象做。
即使我这样做:
DicomSeries * itemSeries = [_context executeFetchRequest:request]
请求包含 DicomSeries
类的实体 @Series
,所以它应该响应:
[itemSeries valueForKey:@type];
但不是。
我觉得有一个巨大的差距CoreData我错过了。我的 NSManagedObjectModel
,我在我的持久存储协调器中使用,我的上下文具有实体系列
,并且 managedObjectClassName
DicomSeries
因此...
lol,wut?
解决我的其他问题,此处。
感谢您的帮助。
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?
The answer to this question was actually solved by solving my other question, here.
Thanks for the help.
这篇关于神秘键值编码键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!