Coder
Coder

Reputation: 529

If else Statement in Swift

I'm a newbie at swift, so how do I add an extra else if statement saying greater than 56 & less than 65 to my button?

The button work fine, it just need one more additional statement added to finished up my coding.

@IBAction func Submit4Button(sender: AnyObject) {

        let a: Float? = (EnterH4Dimension.text as NSString).floatValue

        if a > 65 {

            self.DimensionLabel.text = " Cameron H4 With Guide Pins."

            yesButton.hidden = false
            noButton.hidden = false

            emailButton.hidden = true
            DimensionLabel.hidden = false

            self.view.endEditing(true)

        }

        else if EnterH4Dimension.text == "" {

            noButton.hidden =  true
            yesButton.hidden = true

            var alert = UIAlertController(title: "Dimension", message: "Missing Data Input.", preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

            self.presentViewController(alert, animated: true, completion: nil)

        }

        else {

            self.DimensionLabel.text = "Dimensions meet guideline"

            noButton.hidden =  true
            yesButton.hidden = true

            DimensionLabel.hidden = false
            shallowDimButton.hidden = true
            emailButton.hidden = false
            self.view.endEditing(true)

        }

    }

Upvotes: 0

Views: 15336

Answers (1)

Jérôme
Jérôme

Reputation: 8066

If you are referring to a:

You can try the following:

else if a > 56 && a < 65  {}

Depending on whether or not you want to include 56 and 65 you can use <= & >=

Note that all your else if statements should be place before the final else statement

Upvotes: 2

Related Questions