frostfat
frostfat

Reputation: 185

React-Native Error: [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

I'm coming across an error arising in trying to pass data to Obj-C method.

Code as shown, Obj-C:

RCT_EXPORT_METHOD(connect:(NSDictionary *) params) { 
    _connection = [_phone connect:params delegate:self]; 
}

js:

Twilio.connect({To: '+447842111281'});

The problem stems from handling the NSDictionary, however I can't see a problem with the data. Any insights would be appreciated.

The stack trace is as follows:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d94f34b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010c4f921e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d865d8f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 351
    3   CoreFoundation                      0x000000010d865bfb +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    4   reactNativeRogChapTwilio            0x000000010b783107 -[TCConnectionInternal provideStats] + 1384
    5   reactNativeRogChapTwilio            0x000000010b79fdb9 __21-[TCRTCMonitor start]_block_invoke + 70
    6   libdispatch.dylib                   0x00000001118e40cd _dispatch_client_callout + 8
    7   libdispatch.dylib                   0x00000001118c01c3 _dispatch_continuation_pop + 1091
    8   libdispatch.dylib                   0x00000001118d51e2 _dispatch_source_latch_and_call + 195
    9   libdispatch.dylib                   0x00000001118cdd7d _dispatch_source_invoke + 1098
    10  libdispatch.dylib                   0x00000001118c4b2e _dispatch_main_queue_callback_4CF + 1006
    11  CoreFoundation                      0x000000010d9134f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    12  CoreFoundation                      0x000000010d8d8f8d __CFRunLoopRun + 2205
    13  CoreFoundation                      0x000000010d8d8494 CFRunLoopRunSpecific + 420
    14  GraphicsServices                    0x00000001132cda6f GSEventRunModal + 161
    15  UIKit                               0x000000010ff9df34 UIApplicationMain + 159
    16  reactNativeRogChapTwilio            0x000000010b77d2ef main + 111
    17  libdyld.dylib                       0x000000011193068d start + 1
    18  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Upvotes: 3

Views: 4931

Answers (1)

Trip
Trip

Reputation: 27114

This may or may not be related to your issue. But this error comes a lot for me because the params node data returns without a casted class. Which Objective-C is extremely picky about.

For example, if I put a break point, I get this :

po params[@"callerUserName"]
<extracting data from value failed>

The solution I found was casting it like this :

po ((NSString*)params[@"callerUserName"])

Super curious as to why this happens! Because for some of my methods, data gets passed just fine. But if there's just one integer value within my string ( for example an email with a number in it ), then Obj-C has no idea what to do with itself.

Upvotes: 2

Related Questions