0

Right now I am using the following way declare constants in header file:

static NSString *const RSMaxNumberOfIndustiresKey = @"MaxNumberOfIndustries";

Is it correct? I read Constants in Objective-C question but I really don't know if I really need to declare constant in 2 different places using FOUNDATION_EXPORT.

Community
  • 1
  • 1
Szu
  • 2,254
  • 1
  • 21
  • 37

1 Answers1

1

No. You should use the following in Constants.h:

extern NSString *const RSMaxNumberOfIndustiresKey;

and this in Constants.m:

NSString *const RSMaxNumberOfIndustiresKey = @"MaxNumberOfIndustries";

(i.e. add an implementation file simply to hold the single instance of the string constants).

Using your current method means there is a copy of each string within every file that includes that header.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242