If nil is meant to mark the end of parameters, then can I use:
[NSArray arrayWithObjects:obj1, obj2, nil, nil, nil];
as the first nil marks array end and two nils after will be ignored?
I got two opposite answers and will try it out.
update:
The reason why I need to do this, is I need to create an UIAlertView, which may have buttons: 'OK' only, or 'Call' and 'Cancel', so either 'OK' or 'Cancel', is the cancel button, whereas 'Call' is other buttons in one case, in other cases, I do not need any other buttons, that's why I need to do this.
When you put nil
when creating NSArray
, objects upto that nil
get added. The nil
and objects after that are ignored. Just to complete, you can't add nil
to NSMutableArray
also (say using addObject:
method) and doing that will raise exception.
you can put [NSNull null];
though when creating NSArray.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With