I have a method to construct a post request. That request may have x number of parameters but none of them are mandatory. There are parameters of type boolean (those are passed as strings with values “true” or “false” (not my decision, it is an API).
Here is the problem. My method declaration contains all the parameters that are accepted as part of the post request. The problem is that the request returns different results if a boolean parameter is true, is false or it is not present.
My method id something like
-(void) createRequestWithID:(NSString *)id translate(NSNumber *)translate onlyLastVersions:(NSNumber *)onlyLastVersions
My method is part of a framework which will be used and called by other developers. That means, I cannot control what they pass to parameters such as translate which is a boolean (I use NSNumber as wrapper).
And here comes the problem. I need to be able to identify if the method was called pasing translate as true, false or nil. Because for those cases, I will have the request as translate=”true”, translate=”false” or translate will be not present in the request.
I need a way to differentiate between true, false and nil.
Testing on gbd to try to find a way to differenciate it I get:
(gdb) p translateFALSE
$5 = (NSNumber *) 0x0
(gdb) p translateNIL
$6 = (NSNumber *) 0x0
(gdb) po translateFALSE
Can’t print the description of a NIL object.
(gdb) po translateNIL
Can’t print the description of a NIL object.
(gdb) po [translateFALSE class]
Can’t print the description of a NIL object.
(gdb) po [translateNIL class]
Can’t print the description of a NIL object.
So I see no way to do it.
If you prefer to have this look more like a three-way branch: