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 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.
A bad example would be:
extension List {
public mutating func removeElement(element: Element) -> Element? {
// implementation
}
}
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:
extension List {
public mutating func remove(_ member: Element) -> Element? {
// implementation
}
}
The call to this function looks like this: list.remove(someObject)
.
func addObserver(_ observer: NSObject, forKeyPath path: String)
to which a call would look like `object.addObserver(self, forKeyPath: path)
instead of
func add(_ observer: NSObject, for keyPath: String)
to which a call would look like object.add(self, for: path)