I have an array of NSColors, and an array of CGFloats signifying gradient stops. I can't figure out how to use these arrays to initialize a NSGradient.
I tried making these into an array of (NSColor, CGFloat)s, but NSGradient(colorsAndLocations: won't take it, since it expects varargs:
And NSGradient(colors:, atLocations:, colorSpace:) expects a UnsafePointer which I have no idea how to properly handle in Swift, if there is even such a way.
![The code <code>let gradient = NSGradient(colorsAndLocations: colorsAndLocations)</code> yielding the error <code>Cannot convert value of type '[(NSColor, CGFloat)]' to expected argument type '(NSColor, CGFloat)'</code>](https://i.stack.imgur.com/KrAaL.png)
I assume you know this usage:
Unfortunately, Swift does not provide us a way to give Arrays to variadic functions.
And the second portion. If some API claims
UnsafePointer<T>as an array, you can create a Swift Array of T, and pass it directly to the API.If you want to utilize an
Arrayof (NSColor,CGFloat), you can write something like this: