1
votes

I am getting

Variable 'rollerSmall' was never used; consider replacing with '_' or removing it

error. how do I fix it? It's a warning. I'm trying to do this:

    if roller == "1"{
        var rollerSmall: Bool = true
    }
    if roller == "2"{
        var rollerSmall: Bool = false
        var rollerMedium: Bool = true
    }
        
    }
1
its not an error. Its just a simple awareness by Xcode, because you are not accessing value of rollerSmall no where else in loop. So to save memory allocation its making you aware.Sumit_VE
You are not using rollerSmall anywhere, thus the warning. What do you actually want to achieve with that code?Cristik

1 Answers

0
votes

Variables have scope; it matters where you declare a variable. The problem is that you are declaring your variable inside the if clauses. But you will probably want to declare it, and use it, outside the if clauses. For example:

var rollerSmall = false
var rollerMedium = false
if roller == "1" {
    rollerSmall = true
}
if roller == "2" {
    rollerMedium = true
}
// use rollerSmall and rollerMedium here

Having said all that, this is probably still a terrible way of doing whatever you are trying to do. You should not be encoding things in this flimsy way. If your roller can only have states small and medium, for example, that is an enum and you shouldn't have integer values and different variables at all.