#define vs. global variables

Given that you can define a constant using #define or a global variable (which includes the use of enum), why do Objective-C programmers tend to use global variables? In some cases, there are performance advantages to using global variables. For example, you can use == instead of isEqual: to compare strings if you consistently use the global variable (a pointer comparison is faster than a message send and scanning two strings character-by-character). Also, global variables are easier to work with when you are in the debugger.

In general, you should use global variables and enum for constants, not #define.

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.