Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How will I be able to remove [NSNull Null] objects from NSMutableArray?

I need to remove Null object added by

 [mutArrSkills addObject:[NSNull null]];

Do I need to iterate? Is there any function to remove all null values from NSMutableArray?

If need to Iterate, how will I do that?

like image 922
Heena Avatar asked Feb 08 '12 11:02

Heena


2 Answers

You can use NSMutableArray's removeObjectIdenticalTo: method, as follows

[mutArrSkills removeObjectIdenticalTo:[NSNull null]];

to remove the null values. No need to iterate.

like image 146
Ilanchezhian Avatar answered Oct 23 '22 18:10

Ilanchezhian


removeObjectIdenticalTo:

Removes all occurrences of a given object in the array.

Discussion This method uses the indexOfObjectIdenticalTo: method to locate matches and then removes them by using removeObjectAtIndex:. Thus, matches are determined using object addresses. If the array does not contain anObject, the method has no effect (although it does incur the overhead of searching the contents).

like image 1
Matthias Bauch Avatar answered Oct 23 '22 19:10

Matthias Bauch