本文介绍了目标 C:初始化 NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的代码块,需要将 NSString 设置为一件事或另一件事.在最基本的形式中,它看起来像这样:
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;
但是,我收到使用未声明的标识符‘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.
推荐答案
怎么样?
NSString *outputString;
if (conditionMet){
outputString=@"A";
} else {
outputString=@"B";
}
return outputString;
您需要了解范围
更短的版本:
返回条件满足?@"A" : @"B" ;
它被称为三元条件
这篇关于目标 C:初始化 NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!