0

I've seen this done two ways and I'm trying to decide which one I should implement in my own code.

I've seen people use #Define preprocessor markers...

I've also seen people create static const global variables...

I believe I know how each one works but I'm not sure if there are any drawbacks or benefits to either method or if its just a matter of preference.

Matt Zera
  • 465
  • 3
  • 12
  • There are good arguments for both. Also for enums (and there's a enum typedef macro in the latest Xcode that helps this, though I don't recall the name). – Hot Licks Aug 25 '13 at 00:54
  • The new enum macro: `typedef NS_ENUM(NSInteger, PTAdRequestState) { PTAdRequestStateInactive, PTAdRequestStateLoading }; ` – Hot Licks Aug 25 '13 at 00:58
  • 1
    If you #define a constant, the debugger doesn't see the name. If you make it static const, the debugger knows about the name of the constant. – Fred Aug 25 '13 at 01:04
  • possible duplicate of [Difference between static const and #define in Objective-C](http://stackoverflow.com/questions/12990775/difference-between-static-const-and-define-in-objective-c) – rmaddy Aug 25 '13 at 01:06
  • Hmm... its not a duplicate... that question answers what they are but not the benefits of using one or the other. I'm looking more for why one is better or if one is even better at all. – Matt Zera Aug 25 '13 at 01:26
  • Well... the question you directed too was a duplicate and its counterpart did actually answer my question pretty well. static const variables allow for type checking while preprocessor macros don't. So I guess my question is a duplicate after all. – Matt Zera Aug 25 '13 at 01:30
  • Also check out this question (the title is different, but the question and answers are really about this topic: http://stackoverflow.com/questions/3497088/defining-a-globally-accessible-string-in-objective-c – leanne Aug 25 '13 at 04:48

0 Answers0