Domanda

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";
        }
È stato utile?

Soluzione

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 ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top