Why the print() doesn't work?

“if emptyString.isEmpty {
print("Nothing to see here")
}”
// print nothing like on the pic, what's wrong with it?Thx!

emptyString is not empty. It appears to contain a space.

var emptyString = ""

is how you define an empty string.

5 Likes

@mgstanley Whitespace is considered as a character inside the String. You can confirm this using print(emptyString.count), this should print 0 if the string is truly empty, in your case it's not and it will print 1.

1 Like

thx!I got this

thx! I finally found this problem.