开发者

core data strange unrecognized selector sent to instance

Dear community. I try to pickup some data from managed object context in main AppDelegate from other thread.

    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];

I just read information from main MOC, so, it's can't be a thread-safe trouble, bcs i don't write nothing there. The problem is start just sometime. Here is what i receive as error:

2010-12-16 12:55:05.162 snow[53293:3a0b] -[NSManagedObject isTemporaryID]: unrecognized selector sent to instance 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'


For the sake of anybody else running into this - it's likely that you're passing an NSManagedObject subclass to a method that wants an NSManagedObjectID. Check that your method signatures line up between .h and .m files.


It may not be the actual source of your problem; but ManagedObjectContexts are intended to used one per thread. If you want to access Core Data objects you have to use a separate context for each thread and pass IDs between them.

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


I got this issue by passing in the wrong ID to existingObjectWithID:error:. I was passing in the object's id when I should have used objectID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜