Clear Usage
suggest changeAvoid Ambiguity
The name of classes, structures, functions and variables should avoid ambiguity.
Example:
extension List {
public mutating func remove(at position: Index) -> Element {
// implementation
}
}
The function call to this function will then look like this:
list.remove(at: 42)
This avoids ambiguity. A call such as list.remove(42) would not show whether it removes an element equal to 42 or the element at index 42.
Avoid Redundancy
The name of functions should not contain redundant information.
A bad example would be:
extension List {
public mutating func removeElement(element: Element) -> Element? {
// implementation
}
}
A call may look like list.removeElement(someObject). The argument already shows that an element is removed, so the signature is clearer as:
extension List {
public mutating func remove(_ member: Element) -> Element? {
// implementation
}
}
The call to this function looks like this: list.remove(someObject).
Naming variables according to their role
Name variables by their role (for example, supplier or greeting) instead of their type (for example, factory or string).
High coupling between Protocol Name and Variable Names
If the type’s name is already its role (for example, Iterator), older Swift style added the suffix Type (IteratorType). Current Apple API guidelines drop that suffix.
Provide additional details when using weakly typed parameters
If 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. Example:
func addObserver(_ observer: NSObject, forKeyPath path: String)
A call then looks like object.addObserver(self, forKeyPath: path)
instead of
func add(_ observer: NSObject, for keyPath: String)
A call then looks like object.add(self, for: path).