I want to detect whether passing a NSString to NSLog will return (null). I’ve tried
if (string == @"") {do something}" and if (string == @"(null)") {do something}" but neither seem to work. Any advice would be greatly appreciated!
I want to detect whether passing a NSString to NSLog will return (null) .
Share
Your “NSString” is actually a pointer to an
NSString(i.e. anNSString *). A null pointer in C is simply a pointer with the value0; in C, 0 isfalse, so the following is simple and idiomatic:(p.s.: Your comparisons with
@""and@"(null)"are comparing the addresses of the NSString pointers, not the values; to compare NSStrings, look at-isEqualToString:.)