In Objective C, one could do the following to check for strings:
if ([myString isEqualToString:@""]) {
NSLog(@"myString IS empty!");
} else {
NSLog(@"myString IS NOT empty, it is: %@", myString);
}
How does one detect empty strings in Swift?
There is now the built in ability to detect empty string with
.isEmpty
:Apple Pre-release documentation: "Strings and Characters".
Here is how I check if string is blank. By 'blank' I mean a string that is either empty or contains only space/newline characters.
How to use:
To do the nil check and length simultaneously Swift 2.0 and iOS 9 onwards you could use
What about
For optional Strings how about: