1

I am writing an iOS app, using Swift.

The app crashes some time and what I get in the console is this:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: updated_objectIDs)'
*** First throw call stack:
(0x1858151b8 0x18424c55c 0x1856f5a0c 0x1856ffa40 0x187bc3540 0x187b4edf8 0x187b399bc 0x187b329dc 0x1857c20c0 0x1857bfcf0 0x1857c0180 0x1856ee2b8 0x1871a2198 0x18b7357fc 0x18b730534 0x100069440 0x1846d15b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

I am trying to figure out where this is coming from.

I have no idea at the moment what parts of my code could cause this crash.

What is the proper way to find more information and possibly find the part in code that is causing this crash?

zumzum
  • 17,984
  • 26
  • 111
  • 172

2 Answers2

2

You can create a new Exception breakpoint.This will help you find out line number where the exception is occurring in Xcode.

Check below link for more details.

Xcode doesn't show the line that causes a crash

Objective C - getting line number or full stack trace from debugger error?

So, I have tried the suggested approaches. No luck yet.

Maybe adding the rest of the log can help people getting more information and maybe help me figure out what is going on. This is what I see in the console when the app crashes:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: updated_objectIDs)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010de39d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010d2f521e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010dd4fd87 -[__NSDictionaryM setObject:forKey:] + 1047
    3   CoreFoundation                      0x000000010ddb8729 -[NSMutableDictionary addEntriesFromDictionary:] + 329
    4   CoreData                            0x000000010da00b14 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:deletions:updates:refreshes:deferrals:wasMerge:] + 1844
    5   CoreData                            0x000000010d9646f7 -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 215
    6   CoreData                            0x000000010d962dbf -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 111
    7   CoreData                            0x000000010d93c143 _performRunLoopAction + 339
    8   CoreFoundation                      0x000000010ddde267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    9   CoreFoundation                      0x000000010ddde1d7 __CFRunLoopDoObservers + 391
    10  CoreFoundation                      0x000000010ddc2f8e __CFRunLoopRun + 1198
    11  CoreFoundation                      0x000000010ddc2884 CFRunLoopRunSpecific + 420
    12  GraphicsServices                    0x000000011234fa6f GSEventRunModal + 161
    13  UIKit                               0x000000010f060c68 UIApplicationMain + 159
    14  App                            0x000000010adae2ff main + 111
    15  libdyld.dylib                       0x00000001113a768d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Community
  • 1
  • 1
Chandan kumar
  • 1,074
  • 12
  • 31
  • Did you get anywhere with this? I am looking at a similar problem. Because it is an observer's call to CoreData, and the error is internal to the CoreData library, it is really hard to tell what's actually happening... – John Nimis Jul 30 '18 at 13:31
1

in the exception I'm seeing: setObjectForKey and a key of updated_objectIDs.

There's a couple things I would do to track this down. First thing I might try would be to search for updated_objectIDs and see where it might be getting passed into setObjectForKey.

Then log the address (or description) of the object being passed in at that point and you might catch it as it's happening.

Even better (and what I do in my own work) is to set a breakpoint on all exceptions. You can do it by following the steps in this answer in this closely related question.

Then, when the exception fires, Xcode will stop at that line of code.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215