Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active November 25, 2015 07:41
Show Gist options
  • Save hlung/97adfa8947c22e2286b6 to your computer and use it in GitHub Desktop.
Save hlung/97adfa8947c22e2286b6 to your computer and use it in GitHub Desktop.
iOS - how to create constants in private and public scope
// ----------------------------------
//declaration in PRIVATE scope (for using only in your class)
// ----------------------------------
// declare in .m
static const int kTweetMaxCharacters = 140;
static NSString * const kHelloString = @"HELLO!";
// ----------------------------------
// declaration in PUBLIC scope (for using in other classes too)
// ----------------------------------
// declare in .h
extern const int FGTweetMaxCharacters;
extern NSString * const FGTweetSentNotificationName;
// declare in .m *** Notice there is NO `static`. ***
const int FGTweetMaxCharacters = 140;
NSString * const FGTweetSentNotificationName = @"FGTweetSentNotificationName";
@gruhls508
Copy link

This was handy--first thing I saw on Google to list the syntax for declaring NSTimeInterval constants. Props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment