NSArray arrayWithObjects: if nil is meant to mark array end, can I do …nil, nil]?

前端 未结 4 2075
梦谈多话
梦谈多话 2021-01-03 07:40

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

4条回答
  •  难免孤独
    2021-01-03 08:07

    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.

提交回复
热议问题