+ is unavailable: Please use explicit type conversions or Strideable methods for mixed-type arithmetics
Rather than using the +
operator, you can simply use Strideable.advanced(by:)
.
func increment<T: Strideable>(number: T) -> T {
return number.advanced(by: 1)
}
increment(number: 2) //returns 3
increment(number: 2.5) //returns 3.5