CCSet to CCMutableArray

CCSet to CCMutableArray
0.0 0



I see that CCSet does not have NSSet’s allObjects method that returns an array with the objects contained in the set.

I’ve been looking through CCSet’s implementation and I see that it uses std::set as a backend. Now, std::set can be easily converted to std::vector (as evidenced here for example:, so it would seem that there would be an easy way to convert the CCSet to a CCMutableArray which uses std::vector as a backend.

Unfortunately CCMutableArray does not expose any method that would allow us to send it the initial data as a std::vector.

I port quite a bit of code from Cocos2D to Cocos2D-x and more often than not the code is usually something like:

NSArray *allTouches = [touches allObjects];
UITouch *firstTouch = [allTouches objectAtIndex:0];
// ...
if ([touches count] > 1) 
    UITouch *secondTouch = [allTouches objectAtIndex:1];
    // ... do something between firstTouch and secondTouch

It’s a real pain to jump through hoops and use iterators to get that second touch especially when you want to do something between the touches.

Any chance of getting an allObjects method to CCSet?



Agree. Feature #722 is created.