mardi 24 avril 2018

Swift evaluates wrong a condition at runtime

I am facing the following issue:

I am executing a code where swift has to check if these 2 bools are different isVisible and visible. The values are different but when I print print(isVisible != visible)it gives me false. I have debugged the line of code and when I execute po isVisible != visible it gives me true.

The code that I am using:

func setTabbarVisible(_ visible: Bool) {
    guard let tabBar = tabBarController?.tabBar else {
        return
    }

    let anchorPoint = UIScreen.main.bounds.height - tabBar.frame.size.height
    let isVisible = (tabBar.frame.origin.y == anchorPoint)
    print("SUUU")
    print(isVisible != visible)
    if isVisible != visible {
        UIView.animate(withDuration: kAnimationDuration, animations: {
            if visible {
                tabBar.frame = CGRect(x: tabBar.frame.origin.x, y: anchorPoint, width: tabBar.frame.size.width, height: tabBar.frame.size.height)
                tabBar.alpha = kBarsAlpha
            } else {
                tabBar.frame = CGRect(x: tabBar.frame.origin.x, y: UIScreen.main.bounds.height, width: tabBar.frame.size.width, height: tabBar.frame.size.height)
                tabBar.alpha = 0
            }
        })


    }
}

My debug terminal:

Debug terminal screenshot.

As we can see when I stop the program the values are different and the condition it is true, but when I print the value or the if statement evaluates the condition is giving me false. (I have tried to stop it before the print, and before the if and when I stop it the value is always the same, so it can't be because of concurrency).

Aucun commentaire:

Enregistrer un commentaire