Types & Protocols
Type and protocol names should start with an uppercase letter.
Variables, constants, functions and enumeration cases should start with a lowercase letter.
All naming should use the appropriate camel case. Upper camel case for type/protocol names and lower camel case for everything else.
Upper Camel Case:
Lower Camel Case:
Abbreviations should be avoided unless commonly used (e.g. URL, ID). If an abbreviation is used, all letters should have the same case.
Avoid AmbiguityThe name of classes, structures, functions and variables should avoid ambiguity.
The function call to this function will then look like this:
This way, ambiguity is avoided. If the function call would be just
list.remove(42) it would be unclear, if an Element equal to 42 would be removed or if the Element at Index 42 would be removed.
Avoid RedundancyThe name of functions should not contain redundant information.
A bad example would be:
A call to the function may look like
list.removeElement(someObject). The variable
someObject already indicates, that an Element is removed. It would be better for the function signature to look like this:
The call to this function looks like this:
Naming variables according to their roleVariables should be named by their role (e.g. supplier, greeting) instead of their type (e.g. factory, string, etc..)
High coupling between Protocol Name and Variable NamesIf the name of the type describes its role in most cases (e.g. Iterator), the type should be named with the suffix `Type`. (e.g. IteratorType)
Provide additional details when using weakly typed parametersIf the type of an object does not indicate its usage in a function call clearly, the function should be named with a preceding noun for every weakly typed parameter, describing its usage.
to which a call would look like `object.addObserver(self, forKeyPath: path)
to which a call would look like
object.add(self, for: path)
Using natural languageFunctions calls should be close to natural English language.
Naming Factory MethodsFactory methods should begin with the prefix `make`.
Naming Parameters in Initializers and Factory MethodsThe name of the first argument should not be involved in naming a factory method or initializer.
Naming according to side effects
- Functions with side effects (mutating functions) should be named using verbs or nouns prefixed with
- Functions without side effects (nonmutating functions) should be named using nouns or verbs with the suffix
Boolean functions or variablesStatements involving booleans should read as assertions.
- Protocols describing what something is should be named using nouns.
- Protocols describing capabilities should have
Types and PropertiesTypes, variables and properties should read as nouns.