Pregunta

How should I declare this variable so that I dont get a warning from XCode saying unused variable:

// Set it based on TimeComparator
        if ([TimeComparator dealWithTimeStrings2:locationObject.hor_LV]) {
            NSString * estado = @"Open";
        } else {
            NSString * estado = @"Closed";
        }
¿Fue útil?

Solución

You get the compiler warning and the error because NSString * estado is declared locally in the if-block and locally in the else-block. (Declaring a variable in a { ... } block restricts the visibility to that block.) What you probably meant is

NSString * estado;
if ([TimeComparator dealWithTimeStrings2:locationObject.hor_LV]) {
    estado = @"Open";
} else {
    estado = @"Closed";
}
//... use estado ...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top