Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Type Constraints Swift

//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 by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Type #Constraints #Swift
ADD COMMENT
Topic
Name
7+4 =