Should allKeys() of an empty CCDictionary return NULL or empty CCArray?

Currently, if you have an initialized yet empty CCDictionary and call allKeys() on it, it returns NULL. I would expect it to return an empty CCArray, but is that just me? Often I use allKeys() before iterating through the dictionary so it returning NULL means that I have to check it for NULL before my for loop.

CCDictionary *aDict = CCDictionary::create();
CCArray *allkeys = aDict->allKeys();
for (int i = 0; i < allkeys->count(); i++) {  // <-- this line crashes the app because allkeys is NULL, not empty CCArray
    // some code here
}

Changing this to return an empty CCArray may break some existing code, but it seems more forgiving to the programmer. Thoughts?

Hey, thanks for a heads up. Definitely allKeys() of an empty dictionary should return an empty array.
However I doubt this situation will be changed, since ver 3.x is a primary target now, and AFAIK it uses STL containers instead of Obj-C’s substitutes.

According to the github developer branch, which is for 3.0alpha, the dictionary class still has this issue. I’ve submitted a pull request.

We deprecated Dictionary since 3.0beta, we will not continue to maintain these classes.
We suggest you use the new Template Container of which method keys() will return an empty std::vectorstd::string. Thanks.