Dimitri T Dimitri T - 4 months ago 9
Swift Question

how to include range for eg 'if numbers are between 1 to 5' in swift

I need to code in swift for 'if numbers are between 1 to 5'

I tried this but it's not working.

if myPercent == (1 ... 5) {
let numberGroup = 1


How do I fix this?

Answer

You could just use two conditions to check whether it's in bounds:

if myPercent >= 1 && myPercent <= 5 {
    ...
}