I'm currently using a simple method to test my textfield text like :
extension String {
func test() -> Bool {
return true
}
}
Now if try my function on a concrete String, all is ok
let result = myString.test() //result is a Bool
But if I execute it on an Optional String ( like UITExtField.text
), the type becomes Optional<Bool>
let result = myOptionalString?.test() //result is a Optional<Bool>
Is there a way to provide a default value ( or implementation ) to avoid the test of the result when the caller is Optional
.
I Know I can use some operators like ??
or do an if-else statement, but it's lot of code for nothing
Thanks!