title: Objective-C constant: Xcode build failure for simulator while success in iPhone
body: <p>When I build this 2-class simple iOS project in Xcode 5 for iPhoneSimulator, it reports either  "duplicate symbol _FLAG" or "Undefined symbols _TAG", depends on whether I add "Constant.m" in "Build Phases => Compile Sources" or not. But strangely, it builds successfully for a real iPhone(When add Constant.m in compile sources). Could anybody help me out? I really need to debug my project in a simulator(faster). Thanks.</p>
  
  <pre><code>Constant.h
  #import &lt;Foundation/Foundation.h&gt;
  const int FLAG = 3;
  extern NSString *const TAG;
  @interface Constant : NSObject
  @end
  
  Constant.m
  #import "Constant.h"
  NSString *const TAG = @"hello";
  @implementation Constant
  @end
  
  Deck.h
  #import &lt;Foundation/Foundation.h&gt;
  @interface Deck : NSObject
  + (void)sayHi;
  @end
  
  Deck.m
  #import "Deck.h"
  #import "Constant.h"
  @implementation Deck
  + (void)sayHi
  {
      NSLog(@"%@", TAG);
  }
  @end
  </code></pre>
  
  <p>Updates:(@trojanfoe)
  By <code>extern</code> <code>int</code>s in Constant.h and define the value for them in Constant.m, fixed the build warning. But in return, many codes like <code>switch (i) case CONSTANT</code> does not work. It goes back to <code>#define</code>. Any other approaches will be appreciated. Or any explaination of why build for iPhone is Ok and build for simulator is not? Maybe a "get around" for simulator?</p>
  
  <p>[ANSWER](by @trojanfoe)
  Using <code>enum</code> is a better way to solve the problem. 
  My testing:</p>
  
  <pre><code>Constant.h
  ...
  enum FlagType {FLAG_A = 0, FLAG_B = 1};
  ...
  
  Deck.m
  ...
  switch (i) {
    case FLAG_A:
    //do sth...
    break;
  }
  </code></pre>
  
  <p>Background Info: I want to include a constant header for multiple class. It contains int and NSString. Though #define works, but it's not a good way to use constant. That's why I'm trying as above.</p>