Simple Generic class interface that is using Generic Type Constraints like:
class DoubleRowView<Element: UIView>: UIView {
}
Cause a Minor code smell - Type parameter names should comply with a naming convention
In most cases, type parameters have descriptive names, such as Key
and Value
in Dictionary<Key, Value>
and Element
in Array<Element>
, which tells the reader about the relationship between the type parameter and the generic type or function it’s used in. However, when there isn’t a meaningful relationship between them, it’s traditional to name them using single letters such as T
, U
, and V
, such as T
in the swapTwoValues(_:_:)
function above.
Swift, Generic, Type Constraints