0

where is the right place to define contants in an Xcode project? Such as an URL, that wont change or some images for a different backgroundstyle. AppDelegate.h? If so, where exactly? I'd like to create clean code.

Thanks

Gavin
  • 8,204
  • 3
  • 32
  • 42
Philip
  • 1,068
  • 3
  • 12
  • 21

1 Answers1

0

What about you create a header file, probably constants.h and define your constants in it, for example

#define URL_WEBSERVICE @"http://..."
#define COLOR_TEXT [UIColor colorWithRed:.75 green:1.0 blue:.4 alpha:1.0]
#define MAX_RESULTS 100

You can also import this header file into your precompiled header file .pch so that the values in it become visible to all your files.

McDaddy
  • 144
  • 6
  • If these constants are to be globally visible then this is a perfectly fine solution. If they are specific to a source file, then they should probably just be defined at the top of the source file. If you want them to be visible to any code using a class, then they should be defined in the header file for the class. – Jared Mar 05 '14 at 21:26
  • I like this way of fixing the problem. Very clean! Thanks! I voted. – Philip Mar 06 '14 at 00:14