Wesley Bryant
Wesley Bryant

Reputation: 99

Print Line if output is greater than a certain number

I want to print a line of text into a label if the output is past a certain number (in this case 6). I was thinking of using an if-else statement, but I can't quite figure it out.

Any tips?

Upvotes: 0

Views: 67

Answers (1)

vacawama
vacawama

Reputation: 154631

Here is how you would set the label text to the output value if that value is larger than 6:

if output > 6 {
    label.text = "\(output)"
}

From the comments:

I tried that but I keep getting a bad instruction error. I have my code as:

if output > 6 {
    label.text = "max 6 mg"
}

This usually happens when you have an IBOutlet that isn't hooked up.

@IBOutlet weak var label: UILabel!

Make sure the little circle next to the @IBOutlet on the left is filled in. If it is hollow, drag from the middle of the circle to the label in your Storyboard.

Upvotes: 2

Related Questions