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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -