核心数据奇怪的无法识别的选择器发送到实例

时间:2010-12-16 11:05:50

标签: objective-c core-data

亲爱的社区。我尝试从其他线程中从主AppDelegate中的托管对象上下文中拾取一些数据。

    NSError *error = nil;
    AppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];

    NSFetchRequest *requestCodesList = [[[NSFetchRequest alloc] init] autorelease];
    [requestCodesList setEntity:[NSEntityDescription entityForName:@"CodesvsDestinationsList"
                                            inManagedObjectContext:[appDelegate managedObjectContext]]];
    [requestCodesList setPredicate:[NSPredicate predicateWithFormat:@"(%K.carrier.name == %@) AND (%K.prefix == %@) AND (code == %@) AND (originalCode == %@)",
                                    destinationTypeRelationShipName,
                                    carrierName,
                                    destinationTypeRelationShipName,
                                    prefix,
                                    [destinationParameters valueForKey:@"code"],
                                    [destinationParameters valueForKey:@"originalCode"]]];
                                    //[destinationParameters valueForKey:@"originalCode"]]];
    NSLog(@" Predicate is:%@ START",requestCodesList);
    NSArray *codesInLocalSystem = [[appDelegate managedObjectContext] executeFetchRequest:requestCodesList error:&error];

我刚从主MOC读取信息,所以,这不是一个线程安全的麻烦,bcs我不会在那里写任何东西。问题是在某个时候开始。这是我收到的错误:

2010-12-16 12:55:05.162 snow [53293:3a0b] - [NSManagedObject isTemporaryID]:无法识别的选择器发送到实例0x11836db00

*** Call stack at first throw:
(
    0   CoreFoundation                      0x00007fff84cb47b4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00007fff87ec40f3 objc_exception_throw + 45
    2   CoreFoundation                      0x00007fff84d0e110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
    3   CoreFoundation                      0x00007fff84c8691f ___forwarding___ + 751
    4   CoreFoundation                      0x00007fff84c82a68 _CF_forwarding_prep_0 + 232
    5   CoreData                            0x00007fff85374341 getValueCore + 33
    6   CoreData                            0x00007fff853742e4 _PFCMT_GetValue + 20
    7   CoreData                            0x00007fff8537422d -[NSManagedObjectContext(_NSInternalAdditions) _retainedObjectWithID:optionalHandler:withInlineStorage:] + 45
    8   CoreData                            0x00007fff85376edd _PF_FulfillDeferredFault + 541
    9   CoreData                            0x00007fff8537aab7 _sharedIMPL_pvfk_core + 87
    10  CoreData                            0x00007fff8537ac28 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _genericValueForKey:withIndex:flags:] + 40
    11  CoreData                            0x00007fff853804be -[NSManagedObject valueForKey:] + 270
    12  Foundation                          0x00007fff854b9f6f -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 357
    13  Foundation                          0x00007fff854b9f82 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 376
    14  Foundation                          0x00007fff8551ca22 -[NSFunctionExpression expressionValueWithObject:context:] + 530
    15  Foundation                          0x00007fff854e03a7 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 223
    16  Foundation                          0x00007fff8551c7ba -[NSCompoundPredicateOperator evaluatePredicates:withObject:substitutionVariables:] + 235
    17  Foundation                          0x00007fff8551c690 -[NSCompoundPredicate evaluateWithObject:substitutionVariables:] + 265
    18  CoreData                            0x00007fff85364e41 -[NSManagedObjectContext executeFetchRequest:error:] + 1361
    19  snow                                0x0000000100014a5e -[AppController externalDestinationsForCodeIsAlresdyInLocalDatabaseForCarrierName:withEnabledState:withDestinationParameters:withDestinationTypeRelationShipName:withPrefix:withExternalRateNumber:withAddedDestinations:withCheckForLocalAddedDestinations:] + 862
    20  snow                                0x00000001000158aa -[AppController updateDestinationListforCarrier:destinationType:] + 2586
    21  snow                                0x0000000100015d72 -[AppController makeUpdatesForCarrier:andTypeOfOperation:forDirection:] + 754
    22  snow                                0x00000001000160a1 -[AppController main] + 689
    23  Foundation                          0x00007fff854d3de4 -[__NSOperationInternal start] + 681
    24  Foundation                          0x00007fff855b2beb __doStart2 + 97
    25  libSystem.B.dylib                   0x00007fff84f452c4 _dispatch_call_block_and_release + 15
    26  libSystem.B.dylib                   0x00007fff84f23831 _dispatch_worker_thread2 + 239
    27  libSystem.B.dylib                   0x00007fff84f23168 _pthread_wqthread + 353
    28  libSystem.B.dylib                   0x00007fff84f23005 start_wqthread + 13
)
terminate called after throwing an instance of 'NSException'

3 个答案:

答案 0 :(得分:6)

为了遇到其他任何人 - 你可能正在将NSManagedObject子类传递给需要NSManagedObjectID的方法。检查您的方法签名是否在.h和.m文件之间排列。

答案 1 :(得分:4)

它可能不是您问题的实际来源;但ManagedObjectContexts打算每个线程使用一个。如果要访问Core Data对象,则必须为每个线程使用单独的上下文,并在它们之间传递ID。

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html

答案 2 :(得分:0)

我通过将错误的ID传递给existingObjectWithID:error:来解决此问题。当我应该使用id时,我正在传递对象的objectID