What happens when you pass nil to arrayWithArray:?
Let’s say I have the following code:
NSMutableArray *myArray = [NSMutableArray arrayWithArray:someOtherArray];
If someOtherArray happens to be nil, will myArray be nil or will it be an empty mutable array?
An empty array is returned.
An example implementation of
+arrayWithArray:would be the following:Thus, if
arris null,-countreturns 0, nothing ismalloc‘d, and nothing is copied, because a message sent to a nil object returns the default return value for that type, and does nothing else.