I currently have such a function ...
var currentString: String = ""
func doSomething() {
let newString: String = goGetANewString()
guard newString != currentString else {
return
}
currentString = newString
}
But I find it a little strange that I create newStringoutside guard.
If I translate it in guard, then he complains that it should be optional.
Is there a way to create this newStringinside an operator guardand check the condition?
Ideally, I would like something like this, but, as I said, this does not work.
func doSomething() {
guard let newString: String = goGetANewString(), newString != currentString else {
return
}
currentString = newString
}
source
share