NSMutableSet addObject question

Posted by Jacob Relkin on Stack Overflow See other posts from Stack Overflow or by Jacob Relkin
Published on 2010-10-18T06:14:17Z Indexed on 2011/01/02 4:54 UTC
Read the original article Hit count: 247

I've got a class that wraps around an NSMutableSet object, and I have an instance method that adds objects (using the addObject: method) to the NSMutableSet.

This works well, but I'm smelling a performance hitch because inside the method i'm explicitly calling containsObject: before adding the object to the set.

Three part question:

  1. Do I need to be calling containsObject: before I add an object to the set?
  2. If so, then what actual method should I be using, containsObject or containsObjectIdenticalTo:?
  3. If that is not so, what contains method gets invoked under the hood of addObject:? This is important to me because if I pass an object to containsObject: it would return true, but if I pass it to containsObjectIdenticalTo: it would return false.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about foundation-framework