Abedalkareem Omreyh Abedalkareem Omreyh - 1 year ago 57
Swift Question

Code execute even if where condition is false

I have problem with

if let where
, the code inside the braces execute even if the where condition is false

if let child = value["child"] where child[0]["src"] != nil {
print("Thank you :3")

is nil


I solved the problem by add another let , but still don't get why the code above not work.

if let child = value["child"] ,let src = child[0]["src"] where src != nil {
let imglink = src as! String;
self.content.append(NSURL(string: imglink)!);

Answer Source

Remove where element, you can make multiple check like the below

if let child = value["child"] , source = child[0]["src"] {
     print("Thank you :3")
     print("\(child) - \(source)")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download