变量在Constants.h中
错误是:
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];
答案 0 :(得分:0)
您必须使用extern
来声明头文件中的常量:
extern NSString *const YOUR_CONSTANT;
然后在实现文件(.m
)中定义值:
NSString *const YOUR_CONSTANT = @"Hello World";
并且顺便提一下,您的示例代码对于所有意图和目的都是相同的:
fuelBank1.text = OSVShortTermFuelTrim1;