Type Constraints In Swift Generics

[Solved] Type Constraints In Swift Generics | Swift - Code Explorer | yomemimo.com
Question : Type Constraints Swift

Answered by : samer-saeid

//create a generic function with type constraint
func addition<T: Numeric>(num1: T, num2: T) { print("Sum:", num1 + num2)
}
// pass Int value
addition(num1: 5, num2: 10)
// pass Double value
addition(num1: 5.5, num2: 10.8)

Source : | Last Update : Thu, 23 Jun 22

Question : Type Constraints in Swift Generics

Answered by : samer-saeid

func addition<T: Numeric>(num1: T, num2: T) { ...
}

Source : | Last Update : Thu, 23 Jun 22

Answers related to type constraints in swift generics

Code Explorer Popular Question For Swift