Array NSArrayt, the pitfalls used by NSMutableArray,
In OC development, model is usually used to process data. It is often used to encounter a defined field. For various reasons, the background suddenly changes the field or the null value, resulting in the corresponding value of the model being nil, at this time, if we add this value to the array, we will find that the number of parameters in the array is small, causing crash. In the OC array, if you do not need to pre-apply for adding or deleting an element to the space array, a node is added or deleted. nil indicates the last node, which is not included in the array element. Therefore, if the field is nil, the array element is missing.
NSArray * array = [NSArray arrayWithObjects: @ "1", @ "2", nil, @ "3", @ "4", nil];
NSLog (@ "array ===%@", array );
Output array ==== (
1,
2
)
If you change nil to @ "", no error will be reported.
NSArray * array = [NSArray arrayWithObjects: @ "1", @ "2", @ "", @ "3", @ "4", nil];
NSLog (@ "array ===%@", array );
OutputArray = (
1,
2,
"",
3,
4
)