I am trying to check an NSArray if it contains any object at any particular index and upon checking it i want to insert the object at that particular index if it is empty. Any idea on how to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NSArraydoes not containnilvalues;objectAtIndex:will never returnnil. it is an error to addnilto the collection.To accomplish your task, you could use a placeholder object such as
[NSNull null]as well as querying the array’scount. Of course, you will need anNSMutableArrayto actually perform mutations (e.g. replace or insert).On OS X, you could use
NSPointerArrayto represent a collection which containsnilelements.Example using NSNull: