NSDictionary has the following method signature:
- (NSArray *)objectsForKeys:(NSArray *)keys notFoundMarker:(id)anObject;
My question(s):
- Is nil a reasonable default to use for
notFoundMarker? - Is it possible to get the key (for which no value was found) back as the
notFoundMarkeritself? This is useful if the key and value were are different object types, and lets one know what’s still missing. - Can a block be used as the value for
notFoundMarker, will it actually run? Or will the block’s stack-allocated-address simply be returned? - What are some really bad things to try and use as the value for
notFoundMarker?
As pointed out in the comments below, you should use
[NSNull null]Probably not without writing your own wrapper method or some sort of category to do this. That said, if you just want to know what key wasn’t found, you can simply look at the array of keys that you passed in, as the indexes will match up.
You can certainly use a block. I don’t think it will be run. This should be very easy to test though (simply define a block that logs something out to the console and try it).
This really depends on the context and what you’re doing to do with the returned array. There’s nothing that’s inherently bad to put in an array and return, but I’d question the decision to use anything that doesn’t match the types of the objects you’re expecting to be returned for keys that are found in the NSDictionary.
EDIT:
In fact you could probably achieve what you want for 2. like this: