Then I knew it.
if let a: A = A() { // this is a warning as it treats like always true
print("something") // this line always runs
}
For
if let a = A() { // show an error as the compiler thinks you are missing
something.
}
For me, the first example, explicitly given the type of `a`, so i
I don’t think that explains it (or perhaps I did not understand your response
correctly).
Here is the same issue with a custom type (which does not have a failable
initializer):
struct A { }
if let a = A() { }
// error: initializer for conditional binding must have Optional type, not
I think it did an unnecessary implicitly casting. For example,
let y = Int(exactly: 5)
print(type(of:y)) // Optional
You code equals to
if let y:Int = Int(exactly: 5) { }
However, I don't know why it did that. Maybe because of type inferring?
Zhaoxin
On Fri, Jun 2, 2017 at 8:40 PM, Martin