Search code examples
objective-cxcodecore-datasimperium

Unhandled exception with Simperium


I am having an unhanded exception that is crashing my app with the latest Simperium library. I have setup everything as far as i can tell, but whenever it starts to try and sync core data changes the exception occurs.

Here is the exception that is thrown:

2013-07-31 15:02:00:234 Twitter Translator[28336:303] Simperium enqueuing 168 object requests (Tweet)
2013-07-31 15:07:36.446 Twitter Translator[28336:303] -[AppDelegate handleManagedObjectContextChange:]: unrecognized selector sent to instance 0x102609120
2013-07-31 15:07:36.446 Twitter Translator[28336:303] An uncaught exception was raised
2013-07-31 15:07:36.446 Twitter Translator[28336:303] -[AppDelegate   handleManagedObjectContextChange:]: unrecognized selector sent to instance 0x102609120
2013-07-31 15:07:36.449 Twitter Translator[28336:303] (
0   CoreFoundation                      0x00007fff95799b06 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff897bb3f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff9583040a -[NSObject(NSObject) doesNotRecognizeSelector:] + 186
3   CoreFoundation                      0x00007fff9578802e ___forwarding___ + 414
4   CoreFoundation                      0x00007fff95787e18 _CF_forwarding_prep_0 + 232
5   CoreFoundation                      0x00007fff9574beda _CFXNotificationPost + 2554
6   Foundation                          0x00007fff8c7a27b6 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7   CoreData                            0x00007fff93b1b46f -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 3263
8   Simperium-OSX                       0x00000001001b5251 __34-[SPCoreDataStorage mergeChanges:]_block_invoke + 49
9   libdispatch.dylib                   0x00007fff94d11a2d _dispatch_barrier_sync_f_slow_invoke + 77
10  libdispatch.dylib                   0x00007fff94d0c0b6 _dispatch_client_callout + 8
11  libdispatch.dylib                   0x00007fff94d110c8 _dispatch_main_queue_callback_4CF + 275
12  CoreFoundation                      0x00007fff9573bb4c __CFRunLoopRun + 1644
13  CoreFoundation                      0x00007fff9573b0e2 CFRunLoopRunSpecific + 290
14  HIToolbox                           0x00007fff95247eb4 RunCurrentEventLoopInMode + 209
15  HIToolbox                           0x00007fff95247b94 ReceiveNextEventCommon + 166
16  HIToolbox                           0x00007fff95247ae3 BlockUntilNextEventMatchingListInMode + 62
17  AppKit                              0x00007fff8cc0e533 _DPSNextEvent + 685
18  AppKit                              0x00007fff8cc0ddf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
19  AppKit                              0x00007fff8cc051a3 -[NSApplication run] + 517
20  AppKit                              0x00007fff8cba9bd6 NSApplicationMain + 869
21  Twitter Translator                  0x0000000100005932 main + 34
22  libdyld.dylib                       0x00007fff8a7a37e1 start + 0
23  ???                                 0x0000000000000003 0x0 + 3
)
2013-07-31 15:07:36.449 Twitter Translator[28336:303] *** Terminating app due to uncaught exception      'NSInvalidArgumentException', reason: '-[AppDelegate handleManagedObjectContextChange:]: unrecognized selector     sent to instance 0x102609120'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff95799b06 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff897bb3f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff9583040a -[NSObject(NSObject)     doesNotRecognizeSelector:] + 186
3   CoreFoundation                      0x00007fff9578802e ___forwarding___ + 414
4   CoreFoundation                      0x00007fff95787e18 _CF_forwarding_prep_0 + 232
5   CoreFoundation                      0x00007fff9574beda _CFXNotificationPost + 2554
6   Foundation                          0x00007fff8c7a27b6 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7   CoreData                            0x00007fff93b1b46f -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 3263
8   Simperium-OSX                       0x00000001001b5251 __34-[SPCoreDataStorage mergeChanges:]_block_invoke + 49
9   libdispatch.dylib                   0x00007fff94d11a2d _dispatch_barrier_sync_f_slow_invoke + 77
10  libdispatch.dylib                   0x00007fff94d0c0b6 _dispatch_client_callout + 8
11  libdispatch.dylib                   0x00007fff94d110c8 _dispatch_main_queue_callback_4CF + 275
12  CoreFoundation                      0x00007fff9573bb4c __CFRunLoopRun + 1644
13  CoreFoundation                      0x00007fff9573b0e2 CFRunLoopRunSpecific + 290
14  HIToolbox                           0x00007fff95247eb4 RunCurrentEventLoopInMode + 209
15  HIToolbox                           0x00007fff95247b94 ReceiveNextEventCommon + 166
16  HIToolbox                           0x00007fff95247ae3 BlockUntilNextEventMatchingListInMode + 62
17  AppKit                              0x00007fff8cc0e533 _DPSNextEvent + 685
18  AppKit                              0x00007fff8cc0ddf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
19  AppKit                              0x00007fff8cc051a3 -[NSApplication run] + 517
20  AppKit                              0x00007fff8cba9bd6 NSApplicationMain + 869
21  Twitter Translator                  0x0000000100005932 main + 34
22  libdyld.dylib                       0x00007fff8a7a37e1 start + 0
23  ???                                 0x0000000000000003 0x0 + 3
 )
libc++abi.dylib: terminate called throwing an exception

I think the line where the error is happening is this one:

     dispatch_sync(dispatch_get_main_queue(), ^{
    [__managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
});

But i'm not 100% sure as my bug hunting is not that great :(

Anyone got any ideas?

Thanks

Gareth


Solution

  • This line:

    2013-07-31 15:07:36.446 Twitter Translator[28336:303] -[AppDelegate   handleManagedObjectContextChange:]: unrecognized selector sent to instance 0x102609120
    

    tells you everything you need to know. You are attempting to send the message handleManagedObjectContextChange: to your application delegate, but it doesn't implement that method. So what you need to do is identify where that message is being sent, and to verify that it is indeed being sent to the object you meant to send it to.

    I realize this answer may be a bit general, but you've only supplied one line of code, and it doesn't tell us much. From the looks of the stack trace, identify areas where you are handling notifications; that might be a good place to start looking.