ios - Exception while Passing nil as argument to stringWithString:? -


i have below 2 piece of code

in case application did not crash.

[nsarray arraywitharray:nil]; 

but if passing nil stringwithstring: application crashed.

[nsstring stringwithstring:nil]; 

result uncaught exception 'nsinvalidargumentexception', reason: '*** -[nsplaceholderstring initwithstring:] nil argument'

what reason behind ?

it depends 100% on implementation of method calling if nil parameter allowed. in general passing nil allowed. if rely on non-nil parameter passed in raise exception.

apple / ios developers decided calling arraywitharray:nil result in empty array.
stringwithstring:nil decided not allowed pass in nil , therefore raise exception.

for reason why decided way did, might want go apple developer forums , ask devs there.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -