I have a simple block of code that needs to set an NSString as one thing or another. In it’s most basic form, it looks like this:
if (conditionMet){
NSString *outputString=[NSString stringWithString:@"A"];
} else {
NSString *outputString=[NSString stringWithString:@"B"];
}
return outputString;
But, I’m getting a “Use of undeclared identifier ‘outputString'” error. What is a better way to do this?
I understand this is a pretty basic question, so any quick pointers on how to do this would be terrific. Thanks for reading.
What about ?
You need to learn about scope
Shorter version :
return conditionMet ? @"A" : @"B" ;It’s called ternary condition