-3

the variable is inside Constants.h

enter image description here

ERROR is:

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

and then I am using the above variables in two places, in view controller:

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

and in FuelTrimViewController"

fuelBank1.text = [NSString stringWithFormat:@"%@",OSVShortTermFuelTrim1];
Cœur
  • 37,241
  • 25
  • 195
  • 267
Adeel
  • 123
  • 13
  • @dandan78 dear if u cannot contribute, at least do not disappoint the person who's asking a question, how can this be a duplicate? as i have added my own code snippets. – Adeel Mar 16 '15 at 11:51
  • 1
    @Adeel One could also possibly say if you don't understand the purpose of SO don't use it. The reason they have marked it as a duplicate is because it is the same sort of question and the answer can point you in the right direction. Also do you know what the term `CONSTANT` means? Why are you trying to reassign `OSVShortTermFuelTrim1` when you clearly state it is a constant in your `constant.h` file? Clearly it isn't a constant as you want to be able to reassign those values. Also a constant would be marked with the keyword `const` and `extern`. This `constant.h` file of yours is misleading. – Popeye Mar 16 '15 at 11:59
  • @dandan78 finding an answer is easier then writing it down, i know how to use SO, instead of writing down a duplicate u could have answer this. Thanks anyways. if SO will keep expert guys like you then asking a question over google will result in a single answer by SO with no duplicates. – Adeel Mar 16 '15 at 21:06

1 Answers1

0

You have to use extern to the declare the constants in the header file:

extern NSString *const YOUR_CONSTANT;

and then in an implementation file (.m), define the value:

NSString *const YOUR_CONSTANT = @"Hello World";

and, incidentally, your example code is the same, for all intents and purposes, to:

fuelBank1.text = OSVShortTermFuelTrim1;
trojanfoe
  • 120,358
  • 21
  • 212
  • 242