Answer the question
In order to leave comments, you need to log in
What is the difference in declaring a generic type in Swift?
What is the difference between these two functions? I did not find an answer on the Internet.
Answer the question
In order to leave comments, you need to log in
In the form in which you gave them, the functions do not differ .
The parameter on the right specifies the type of T , in the tutorials this is called a type constraint .
static func max1<T:Comparable>(a: T, b: T) -> T {
return a < b ? b : a
}
static func max2<T:Comparable>(a: T, b: T) -> T where T : Equatable {
return a < b ? b : a
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question