Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add object to array only if the object is not in already

I want to add object to array only if the array already does not contain that object. How to do opposite of containsObject method in NSArray ?

like image 440
OhDoh Avatar asked Dec 02 '25 05:12

OhDoh


1 Answers

Use an NSMutableOrderedSet, whose addObject: method does exactly what you want:

Appends a given object to the mutable ordered set, if it is not already a member.

like image 88
jscs Avatar answered Dec 03 '25 21:12

jscs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!