Put constants with things that use them. Do not create the global "all constants" file. This makes code reuse a huge headache. For example, if you are sending a notification, you need a notification name string. So you put this in a class that sends a notification:
.h extern NSString * const MYObjectDidSomethingNotification; .m NSString * const MYObjectDidSomethingNotification = @"MYObjectDidSomethingNotification";
Constants are usually not methods or do not define. These are just constant global variables as shown above. You should avoid #define wherever possible, but there are some places that are very useful (for example, persistent UIColor
objects that otherwise disappoint initialization).
Spend some time in Apple's header files to see examples. Take a look at UIWindow.h, UITableViewCell.h, and UITableView.h for some good examples of how constants are usually defined.
source share