1

What's the best practice for the use of some static info like:

  • Server base url
  • Some path file
  • ...

I think that we can found some different solutions for this:

  1. It's possible to add these informations in plist file;

  2. It's possible to add some #define in file ..Prefix.pch of our iOS app;

  3. It's possible to create a file constant.h where we can add our #define(s) and add the #import "constant.h" into every file where you need to use some of these information or add this import directive into the same Prefix.pch file

exist some best practices for this? What is the best of these?

Safari
  • 11,437
  • 24
  • 91
  • 191

2 Answers2

3

I prefer something similar to solution 3:

Create a Constant file, which you include in the Prefix.pch.

Though I really hate the #define approach.

Instead, in Constants.h use:

extern NSString* const kStringConstant;

and define it in Constants.m:

NSString* const kStringConstant = @"SomeStringConstant"

This answer explains why you shouldn't use #define.

Community
  • 1
  • 1
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
1

I use solution with Constants.h file that contains all global constants defined with #define. Also Constants.h is included in Prefix.pch file. Dealing with plist can sometimes require more code than just writing constant, but on the other hand can be a cleaner solution.

Josip B.
  • 2,434
  • 1
  • 25
  • 30