我有尝试在“_result”中设置结果的方法。如果我使用格式化的字符串将其分配给“_result”,则会出现错误“表达式结果未使用”。如果我使用纯字符串作为@“done”,则错误不会显示,并且NSlog正确打印了字符串,这给我带来了问题。
有什么建议我可以解决这个问题吗?谢谢!
@property (nonatomic) NSString * result;
@synthesize result = _result;
- (NSString *) _result
{
if (!_result) {
_result= [[NSString alloc] initWithFormat:@"Could not compare %e"];
}
return _result;
}
- (NSString *) comparePrice:(double) price_one to_price2:(double) price_two;
{
if (price_one > price_two) {
NSLog(@"LOG result is %e ",price_one);
_result = @"result is %e ",price_one;
_result = @" done";
}
return _result;
}
最佳答案
您的错误在此行上:
_result = @"result is %e ",price_one;
编译器不知道如何使用“
price_one
”位。您需要指示编译器您正在尝试使用格式字符串。将该代码行更改为:
_result = [NSString stringWithFormat: @"result is %e ",price_one];
你应该很好
关于ios - 使用变量时NSString中的“Expression myExpression未使用”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433147/