When comparing strings in Swift, you can compare non-optional strings with optional strings.
Like so (text is an optional, and it is empty):
UITextF
Your theory doesn’t hold in the following example:
let x: String? = nil
if x == "" {
print("True")
} else {
print("False") //Printed
}
What’s actually happening here is that the text property is never actually nil upon initialisation — it is instead an empty string, as given by the documentation:
This string is @"" by default.
The Swift compiler does not implicitly unwrap any optionals, it instead leaves that responsibility to the programmer.