I would like to use the Accelerate framework to extend [Float] and [Double], but each of them requires a different implementation.
I tried the obvious:
extension Array<Float> { }
and get this error:
"A restricted extension must be declared on a non-specialized generic type 'Array' with the restrictions specified in the 'where' clause
Is it possible to distribute generic types in Swift 2 this way?
The code now works for me as expected. Here is an example of summing using the Accelerate view.
extension _ArrayType where Generator.Element == Float { func quickSum() -> Float { var result: Float = 0 if var x = self as? [Float] { vDSP_sve(&x, 1, &result, vDSP_Length(x.count)) } return result } } extension _ArrayType where Generator.Element == Double { func quickSum() -> Double { var result: Double = 0 if var x = self as? [Double] { vDSP_sveD(&x, 1, &result, vDSP_Length(x.count)) } return result } }
generics swift swift2 swift-extensions
GScrivs Aug 04 '15 at 10:04 2015-08-04 10:04
source share