How can I write a function that takes generic type arguments, but returns a different type based on what the generic object's type is? [duplicate]
问题 This question already has answers here : How can I handle different types using generic type in swift? (2 answers) Closed 3 years ago . I'm trying to write a basic interpolation function in swift3. I get a lot of errors, though. This is obviously not the right way to use generics, but maybe I have a fundamental misunderstanding of their application? class func interpolate<T>(from: T, to: T, progress: CGFloat) -> T { // Safety assert(progress >= 0 && progress <= 1, "Invalid progress value: \