- I have this bug in Obj-C that is caused because the program is trying to access a non-existing NSArray key.
- Typically in my PHP programs I verify that a key exists before using it using array_key_exists(NEEDLE, HAYSTACK).
- Is there an equivalent in Cocoa / Obj-C for these two functions, and if not, how would you go about creating these.
- I am more interested in a solution for array_key_exists() than in array_search().
I have this bug in Obj-C that is caused because the program is trying
Share
In an NSArray, keys can only be integers. So you can simply check whether the index you are trying to access is less than the number of items in the array. You can check the number of items via the count method: