Вопрос

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";
        }
Это было полезно?

Решение

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 ...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top