获取的属性和多个 ManagedObjectContext
)
出于多种原因,我必须创建 2 个 ManagedObjectContext,每个都有一个不同的 NSPersistentStoreCoordinator(一个是 NSSqlLiteType,另一个是 NSInMemoryType)。 SQLLite 数据库的某些对象必须访问 InMemory 数据库中的对象。我在苹果文档中找到了一种使用获取的属性使其工作的方法(所以他们说,请查看此处的“跨商店关系”段落:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html)。 问题是,当执行谓词时,我收到一个符合 KVC 标准的错误:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ valueForUndefineKey:]:此类不符合 key stationId 的键值编码。”
这是模型。 我有一个存储在 SQL Lite 数据库中的 ManagedStation 对象。我有一个存储在内存中的 ManagedPassingTime 对象。 ManagedStation 应该有一个 ManagedPassingTimes 的 NSSet。为此,我向 ManagedPassingTime 添加了 stationId 属性。加载 Station 时,我创建所需的 ManagedPassingTime 对象并将 ManagedPassingTime 的 stationId 设置为 ManagedStation.identifier 属性。最后,我在 ManagedStation 对象中创建了一个获取的属性“passingTimes”,该对象具有以下谓词:$FETCH_SOURCE.identifier MATCHES $FETCHED_PROPERTY.stationId。获取的属性将 ManagedPassingTime 对象设置为 Destination。
由于stationId是ManagedPassingTime的一个属性,我不明白为什么不能使用KVC访问该值。我什至尝试重写 ManagedPassingTime 中的 valueForUndefiniedKey:(NSString*)key 方法,但似乎我从未输入过此方法。
如果你们中的任何人有哪怕是最微小的想法,那都会很有帮助。 谢谢。
)
for several reasons, I have to create 2 ManagedObjectContext, each one having a different NSPersistentStoreCoordinator (one is NSSqlLiteType, the othe is a NSInMemoryType).
Some objects of the SQLLite database have to access to objects in the InMemory database. I found in the Apple Documentation a way to make it work using fetched properties (so they say, look at the "Cross-Store Relationships" paragraph here : http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html).
The thing is, when the predicate is executed, I get a KVC compliant error :
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key stationId.'
Here's the model.
I have a ManagedStation object which is stored in the SQL Lite database. I have a ManagedPassingTime object which is stored in memory. The ManagedStation is supposed to have a NSSet of ManagedPassingTimes. To do so, I added a stationId attribute to the ManagedPassingTime. When loading a Station, I create the needed ManagedPassingTime objects and set the stationId of the ManagedPassingTime to the ManagedStation.identifier property. Finally, I created a fetched property "passingTimes" in the ManagedStation object which has the following predicate : $FETCH_SOURCE.identifier MATCHES $FETCHED_PROPERTY.stationId. The fetched property has the ManagedPassingTime object set as Destination.
Since stationId is an attribute of ManagedPassingTime, I don't understand why the value cannot be accessed using KVC. I even tried to override the valueForUndefiniedKey:(NSString*)key method in ManagedPassingTime, but it seems that I never enter this methods.
If any of you guys has even the tiniest idea, it would be most helpful.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我昨天遇到了这个问题,我让它工作的方式实际上是省略了 $FETCHED_PROPERTY。
因此,在您的情况下尝试
$FETCH_SOURCE.identifier MATCHES stationId
看来您不需要在 xcode 4 中使用 $FETCHED_PROPERTY,也许它假设任何未指定的对象都在获取的属性上。如果他们能更新 xcode4 的文档就好了。
I ran into this yesterday and the way I got it to work was actually leaving off the $FETCHED_PROPERTY.
So in your case try
$FETCH_SOURCE.identifier MATCHES stationId
It seems you don't need to use the $FETCHED_PROPERTY in xcode 4, maybe it assumes that any unspecified objets are on the fetched property. Would be nice if they'd update the documentation for xcode4 though.