coopersita
coopersita

Reputation: 5041

'setObjectForKey: key cannot be nil' exception, how to tell which one

My app is randomly (sometimes it does, sometimes it doesn't) crashing:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010988ec65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010b63bbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000109793af8 -[__NSDictionaryM setObject:forKey:] + 968
    3   MultipeerConnectivity               0x00000001096e32e2 -[MCNearbyServiceBrowser netServiceBrowser:didFindService:moreComing:] + 251
    4   CFNetwork                           0x000000010c2ca2dd -[NSNetServiceBrowser _dispatchCallBack:flags:error:] + 968
    5   CFNetwork                           0x000000010c217fe2 _ZL14_BrowserCancelP21__CFNetServiceBrowser + 133
    6   CoreFoundation                      0x00000001097c2431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    7   CoreFoundation                      0x00000001097b82fd __CFRunLoopDoSources0 + 269
    8   CoreFoundation                      0x00000001097b7934 __CFRunLoopRun + 868
    9   CoreFoundation                      0x00000001097b7366 CFRunLoopRunSpecific + 470
    10  GraphicsServices                    0x000000010d1a3a3e GSEventRunModal + 161
    11  UIKit                               0x000000010a36f8c0 UIApplicationMain + 1282
    12  MyApp                               0x0000000109099137 main + 135
    13  libdyld.dylib                       0x000000010cccc145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

How can I tell in Xcode which line of code, or collection object is causing the problem?

Update

I did as the answer and comments suggested, and added the breakpoint with the command, and now, before the error, I get this:

*** setObjectForKey: key cannot be nil

4354859399

3534170

140567501647968

140567492355160

140567492355168

4354751672

4294967279

I still don't know what that means...

Upvotes: 2

Views: 2723

Answers (1)

Quentin Hayot
Quentin Hayot

Reputation: 7876

In your Xcode's left panel, go to the Breakpoints tab, click the + button and add an Exception Breakpoint. It will catch any exception and tell you where they occur.

enter image description here

Upvotes: 4

Related Questions