Are there any useful naming conventions for * your * constant / static variable in Cocoa?

I know that constants start with a prefix k, but does someone have their own constant prefix, so they can easily get terminated on their constants, and not on Apple?

I use a three-letter prefix for my classes because of the name of my company, let it pretend OMG. I tried the prefix of my constants omgkConstantName, but this is not very nice. I also played with kkor ok(o from OMG.) Or maybe I should do kOMGConstantName, which looks more Cocoa -ish?

It seems very useful to quickly get to your own constants, just as you might want to get to your own classes. Does anyone do this? Is this a terrible Cocoa style?

Also, is there a good naming convention for static variables that you would use in only one class, like keys for a JSON dictionary? Should they have k? Should they start with capital letters or follow normal cases?

// Static Variables
static NSString *searchTextKey = @"searchText";
static NSString *searchResultsKey = @"searchResults";
(more)
+5
source share
4 answers

kJAFoo ( kXXFoo, XX - ) - const, , - kFoo static const . , sFoo gJAFoo , .

, ( ), , .

+6

Apple Cocoa , . , OMGConstantName .

+6

.

" " , .

,

static NSString *SearchTextKey = @"searchText";

, ( ZK)

static NSString *ZKSearchTextKey = @"searchText";

, , , Google (, , , ).

Most importantly, however, that you agree to any agreement. Stick to this and be consistent (at least as part of this project). At some point, second guessing yourself will simply waste time.

+2
source

I usually follow the same prefix / capitalization convention as classes, so when Cocoa has NSTouchPhaseBegan, I could have GLTuneNameKey.

+1
source

All Articles