For example, the method:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
in UIResponder has an NSSet* touches as the parameter.
In the method itself, how do I determine what type of object touches actually contain? In this case, it contains a set of UITouch. But I knew that from reading some tutorials online.
In general, how do I know what kind of object the set contains?
As Aran said, you can use
isKindOfClass:to determine the type of the items in an NSSet. Or you can ask any given item for its-classand go that route.But don’t.
Throughout Cocoa, it is exceedingly rare to see code that changes behavior based upon the class of an item where the class is not determined as part of the software design process.
Thus, whenever code is using
isKindOfClass:to handle various items in a collection, it is almost always an indication of an architectural issue — almost always an indication that the code is using patterns that are either sub-optimal or otherwise alien to Cocoa.