I encountered this problem today. Despite assigning a string to be nil: NSString *str = nil;, the test if (str == nil) returned FALSE! Changing the test to if (!str) worked, however.
It seems that my string in the debugger was reporting as (null) but that was due to how it was being assigned, I fixed it and now it is reporting as nil. This fixed my issue.
you may check your getting string using this
Is it possible that your string is not in fact
nil
, and is instead just an empty string? You could try testing whether[myString length] == 0
.I encountered this problem today. Despite assigning a string to be nil:
NSString *str = nil;
, the testif (str == nil)
returnedFALSE
! Changing the test toif (!str)
worked, however.You can implicitly check for
nil
(allocated, but not initialized) with this:If
myString
was assigned from a dictionary or array, you may also wish to check forNSNULL
like this:Finally (as Sophie Alpert mentioned), you can check for empty strings (an empty value):
Often, you may want to consolidate the expressions:
You can find more on objective C string here.
It seems that my string in the debugger was reporting as (null) but that was due to how it was being assigned, I fixed it and now it is reporting as nil. This fixed my issue.
Thanks!