checking for nil and getting ‘unexpectedly found nil while unwrapping an Optional value’

I’m checking if an optional value is nil before unwrapping it

        //check if it's nil
        if voteStatus == nil {
        } else {
            cell.setStatus(voteStatus!); //crash here, why?
            if voteStatus == 1 {
            } else {

However, it crashes at this line:


with error:

unexpectedly found nil while unwrapping an Optional value

Doesn’t make any sense to me because I’m checking if it’s nil above before unwrapping it.

What am I doing wrong?

Source: ios

Leave a Reply