how to pass a quick table like UnsafePointer & lt; T & gt; argument in a...
source link: https://www.codesd.com/item/how-to-pass-a-quick-table-like-unsafepointer-t-argument-in-a-function.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
how to pass a quick table like UnsafePointer & lt; T & gt; argument in a function
I read that in order to pass a swift variable/constant to an argument that expects UnsafePointer can be done by using the 'inout' (ampersand) symbol prefixing the variable/constant. So in the following code, I want to pass the 'colors' array as "UnsafePointer' to the function CGGradientCreateWithColorComponents(), but I get a compiler error:
"& used with non-inout argument of type UnsafePointer"
See image below for visual.
So, the question is , how can I convert the swift array 'colors' into an UnsafePointer ?
thanks
Change your colors type to be explicitly [CGFloat]
:
var colors : [CGFloat] = [0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0]
No need to deal with &
or anything. But you have to actually pass in an array of CGFloat
.
And don't pass in NULL
but nil
:
let gradient = CGGradientCreateWithColorComponents(baseSpace, colors, nil, 2)
Related Articles
How do I make a table like this?
How to pass listview in table?
How to download a large table like MySQL in my pc?
How to pass the 2D table as a Range for Google Spreadsheet Chart?
how to pass the parameter method to display () in the resource controller of another function
How to pass the URL of dynamically generated anchor tags to the jQuery hover () function ??
How to pass a variable in the program c as an argument of the batch file?
Pass the path to the file / filename as an argument to a function that prints the file on the screen in C ++
Passing a pointer to a char array as an argument to a function - C
How to pass a temporary table in a stored procedure without pk
How to pass through a table return from the mysql query
Cakephp - How to pass through the table in the mail template?
how to pass this structure table to function, what wrong with my code?
How to pass a 2d table between activities?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK