How to create a CIVector from array of CGFloat?

2.4k views Asked by At

I am trying to create the CICrossPolynomial filter type in Swift.

I am unsure how to create the syntax to do it however.

The documentation specifies a CIVector which has an array of floats?

A CIVector object whose display name is RedCoefficients.

Default value: [1 0 0 0 0 0 0 0 0 0] Identity: [1 0 0 0 0 0 0 0 0 0]

But how do I actually declare such a CIVector? There is one constructor that has this signature

CIVector(values: <UnsafePointer<CGFloat>>, count: <UInt>)

But when I try

var floatArr:Array<CGFloat> = [1,0,0,0,0,0,0,0,0]
var vector = CIVector(values: floatArr, count: floatArr.count)

I get the error:

Cannot invoke 'init' with an argument list type (values: @lvaue Array<CGFloat>, count:Int)

Do you know how I can properly create a CIVector with an array of CGFloats?

1

There are 1 answers

0
Martin R On BEST ANSWER

floatArr.count has the type Int, but the count: parameter has the type UInt, therefore you need to convert it explicitly:

let floatArr: [CGFloat] = [1,0,0,0,0,0,0,0,0]
var vector = CIVector(values: floatArr, count: UInt(floatArr.count))