Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLevi Kline
2,825 PointsWhat does this code mean?
I had a long code using if statements to return based on if something was left empty. Then, my friend gave me this code:
func hasFilledPassword(text: String = "") -> Bool {
let text = text
return !(text == "")
}
what does the last part mean, please explain
dipanchokshi
3,216 Pointsdipanchokshi
3,216 PointsLet me make parts of it
Part-1:
text == ""
means it will compare text with empty string. If it is empty then it will return true else false.Part-2:
!
will maketrue
tofalse
and vice versa.so lets consider below scenario
if your text has empty string then
!(text == "")
will become!(true)
and it will returnfalse
.if your text has some string then
!(text == "")
will become!(false)
and it will returntrue
.