Sorry if this is a noob question, because I am new to Swift and cannot find this answer from Google.
When I first saw the guard, I was thinking about inversion ifin another programming language.
var optString: String?
guard optString != nil else { return }
if optString == nil { return }
Does the second and third row produce the same result?
I can understand if letmaking the code easier than checking niland deploying it, but what is the purpose guard? From what I explored, I can only find people saying that he can reduce the nested if, which invert if, can do the same.
EDIT: I'm asking about inversion if NOT if let . Please read before marking it.
source
share