In Objective-C, are there any ways to indicate that an NSNumber* should actually be a BOOL? Right now my code looks like:
NSNumber *audio; // BOOL wrapper
Without the comment, it is not immediately obvious that *audio is a boolean value.
My first thought was to try
typedef NSNumber* BOOL;
but this gave a compiler error apparently because typedef doesn’t understand Objective-C.
Without changing the variable names (which is difficult when using existing APIs), how should I indicate that an NSNumber* holds a boolean value?
The code:
doesn’t compile because BOOL is already a typedef, and it’s not allowed to redefine a typedef.
So you could use another name for that type, e.g.:
Or, probably better, name the variable so that you know it is an NSNumber and contains a bool, this way you don’t even need to go look for the variable type: