Search code examples
swiftif-statementlet

Only else-block of "if let"?


In a cellForRowAtIndexPath I have:

if let imageView = cell.viewWithTag(SOME_TAG) as? UIImageView
{
    // Nothing to do here.
}
else
{
    // Add image view to cell.
}

but I only need the else block. Is there a way to invert a if let xyz =?

(I know I could break it up and have a if imageView == nil.)

Just found this similar question.


Solution

  • Something like this?

    if cell.viewWithTag(SOME_TAG) == nil {
    
    }