Code Naming Basics

An often overlooked aspect of the design of object-oriented software libraries is the naming of classes, methods, functions, constants, and the other elements of a programmatic interface. This section discusses several of the naming conventions common to most items of a Cocoa interface.

General Principles



See also “Method Arguments.”

No Self Reference


Prefixes are an important part of names in programmatic interfaces. They differentiate functional areas of software. Usually this software comes packaged in a framework or (as is the case of Foundation and Application Kit) in closely related frameworks. Prefixes protect against collisions between symbols defined by third-party developers and those defined by Apple (as well as between symbols in Apple’s own frameworks).

Typographic Conventions

Follow a few simple typographical conventions when naming API elements:

Class and Protocol Names

The name of a class should contain a noun that clearly indicates what the class (or objects of the class) represent or do. The name should have an appropriate prefix (see “Prefixes”). The Foundation and application frameworks are full of examples; a few are NSString, NSDate, NSScanner, NSApplication, UIApplication, NSButton, and UIButton.

Protocols should be named according to how they group behaviors:

Header Files

How you name header files is important because the convention you use indicates what the file contains: