Abedalkareem Omreyh Abedalkareem Omreyh - 3 months ago 9
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")
continue
}


the
child[0]["src"]
is nil

Edit


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)!);
continue
}

Answer

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)")
     continue
   }