Swift 6 · Types and protocols

Generics

Write a function once for any type that meets a constraint.

func largest<T: Comparable>(_ items: [T]) -> T? {
    items.max()
}

Official Swift 6 documentation

More types and protocols commands

All types and protocols commands · Swift 6 cheatsheet

Was this page helpful?