Assume you have a Singleton
Constants class, instance of which you\'d like to use throughout your application.
In someClass
, therefore we
Following @vinceburn I would use the following example for constants and a singleton for more complex structures.
// Constants.h
// Replace PSMyApp for something more useful. e.g. company/name initials followed by app/class
// String example
NSString * const PSMyAppString = @"constantString";
// Logically related integers
typedef enum {
PSMyAppRelatedValuesOne = 0,
PSMyAppRelatedValuesTwo,
PSMyAppRelatedValuesThree
} PSMyAppRelatedValues;
// Float example
const CGFloat PSMyAppFloat = 0.3f;
// Integer that has no related values
const NSInteger PSMyAppInteger = 2;
I prefer this over #define
as I get auto completion and compiler checking and it fits more naturally with the way Apple does thing in some of the UIKit
classes.