Fetched Property and multiple ManagedObjectContext
)
for several reasons, I have to create 2 ManagedObjectContext, eac开发者_如何学JAVAh 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.
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.
精彩评论