You can check if [string length] == 0 . This will check if it's a valid but empty string (@"") as well as if it's nil, since calling length on nil will also return 0. There are some very rare NSStrings where this will result in a false negative (saying the string isn't empty, when, for practical purposes, it is).
Like NSNumber, NSString is also immutable type. It's used to represent text in Objective-C. NSString provides built-in support for Unicode, which means that we can include UTF-8 characters directly in string literals.
My code is reading a list of key/value pairs like follows:
A:nodeAbc
...
Q:node2
R:
T:node3
...
Each pair is split using NSString:componentsSeparatedByString:
NSArray *kv = [@"R:" componentsSeparatedByString:@":"];
In the list example above, R has no matching value. As I ask to print it, here is what I get:
(lldb) po [kv objectAtIndex:1] (id) $33 = 0x00007fff77a888e0
How can I identify this?
if ([kv objectAtIndex:1]) // returns YES
I'd like it to be treated as a nil, how can it be done? Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With