Sandeep
Sandeep

Reputation: 21144

Passing CGFloat array in core graphics

There are many functions in core graphics that take the pointer ie. pointer of array such as CGContextSetFillColor(context, colors);. I have to create the value for the array colors everytime and then pass the pointer to the function as;

CGFloat colors[] = {1.0, 0.0, 0., 1.0};
CGContextSetFillColor(context, colors);

But, it would be much easier if I could pass the values directly into the functions like;

CGContextSetFillColor(context, {1.0, 0.0, 0., 1.0});

The above syntax is not correct and the compiler complains about it, I have very limited understanding of how pointers work in C. So I would like to ask what is the correct way to pass the values directly in the same line.

Upvotes: 1

Views: 351

Answers (1)

Egor Chiglintsev
Egor Chiglintsev

Reputation: 1252

According to the information from this answer on this question you can do this:

CGContextSetFillColor(context, (CGFloat[]){1.0, 0.0, 0., 1.0});

Upvotes: 6

Related Questions