How to test for a (null) string in Objective C

I wanted to test if a string has a value when it’s returned from Core Data. So I thought, the right way to do this was to see if it’s equal to nothing, like so:

But to my surprise this didn’t work – because my string was (null) rather than “empty” or nil, which in Objective C are not the same thing.

Instead we can test for the length of this string, and if it returns zero, then we’re sure it’s empty:

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!