如何在目标c中修复此错误?

时间:2015-03-16 11:34:20

标签: objective-c

变量在Constants.h中

enter image description here

错误是:

duplicate symbol _OSVShortTermFuelTrim1 in:
/Users/loximity/Library/Developer/Xcode/DerivedData/AutoCodesApp-hjoxbttreaujifdypikhbngdqihd/Build/Intermediates/AutoCodesApp.build/Debug-iphonesimulator/AutoCodesApp.build/Objects-normal/i386/ViewController.o
/Users/loximity/Library/Developer/Xcode/DerivedData/AutoCodesApp-hjoxbttreaujifdypikhbngdqihd/Build/Intermediates/AutoCodesApp.build/Debug-iphonesimulator/AutoCodesApp.build/Objects-normal/i386/FuelTrimViewController.o

然后我在两个地方使用上面的变量,在视图控制器中:

OSVShortTermFuelTrim1 = [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]];

并在FuelTrimViewController“

fuelBank1.text = [NSString stringWithFormat:@"%@",OSVShortTermFuelTrim1];

1 个答案:

答案 0 :(得分:0)

您必须使用extern来声明头文件中的常量:

extern NSString *const YOUR_CONSTANT;

然后在实现文件(.m)中定义值:

NSString *const YOUR_CONSTANT = @"Hello World";

并且顺便提一下,您的示例代码对于所有意图和目的都是相同的:

fuelBank1.text = OSVShortTermFuelTrim1;