Marc Charbonneau
You can check if [string length] == 0. This will check if it is a valid but empty string (@"") and if it is null. Because calling length with no value will also return 0.
Matt G
The answer above is correct. But I would like to take this opportunity to introduce isEmpty summarized by Wil Shipley, which he shared on his blog:
The first method is effective, but it will not work if the string has spaces (@" "). So the spaces must be cleared before testing.
The following code can remove all spaces on both sides of the string
Marc Charbonneau
You can check if [string length] == 0. This will check if it is a valid but empty string (@"") and if it is null. Because calling length with no value will also return 0.
Matt G
The answer above is correct. But I would like to take this opportunity to introduce isEmpty summarized by Wil Shipley, which he shared on his blog:
The first method is effective, but it will not work if the string has spaces (@" "). So the spaces must be cleared before testing.
The following code can remove all spaces on both sides of the string
A good way is to define a macro so that you don’t have to enter this long string of code:
Now you can use:
Rob
One of the best workarounds I've seen (better than Matt G's) is this improved inline function, which I found in a Git Hub report:
user238824
You'd better use this function:
chown
Another option is to use isEqualToString to check if it is equal to @"", like this:
Jim Thio
This one I use:
The problem is that if self has no value, this function will never be called. It will return false, which is required.
Samir Jwarchan
Just use one of the following if else conditions:
Method 1:
Method 2: