I'm working on an API which includes a lot of block arguments with its interface. I decided the library should accept nil
for block arguments. So it is necessary to check for nil
before calling any block in the implementation.
However, the code would become quite ugly if there is a lot of if
.
if (completionHandler) {
completionHandler(userInfo, success, error)
}
one line of code would become 3 lines.
I'm currently using such a macro definition to avoid this,
#define completionHandler(...) if (completionHandler) completionHandler(__VA_ARGS__)
It works well. But this technique limits the name of my callbacks to "completionHandler"
. Is there an more elegant and also safe way to support arbitrary callback names?
Does any one have any suggestions on nil
checking?