Hey Chris,
So I work with a C library and Swift as well and have a couple of ideas for
you depending on how you work with the array. Here are some tricks I have
used when passing around arrays from C to Swift to ObjC and never had
issues with it. Also, while passing in the first element of the
Hi Chris,
Yes, he'll need to do
withUnsafeMutablePointer(to: ) {
transformationTuplePtr in
withUnsafeMutablePointer(to: ) {
projectionTuplePtr in
transformationTuplePtr.withMemoryRebound(to: Float.self, capacity: 16) {
transformationArrayPtr in
Sorry to jump in here, and maybe I’m missing something obvious, but in your
example Rick is two levels of closure deep and only has access to one of the
arrays in his struct. In this case there is another array of floats he needs as
an argument to his method call. Will he need to go through the
Hi Rick,
> On 21 Sep 2017, at 1:03 am, Rick Mann via swift-users
> wrote:
>
> I've got Swift code wrapping a C API. One of the C structs the API uses looks
> like this:
>
> typedef struct {
>size_t size;
>float transformation[16];
>float projection[16];
>
Adding: it seems that while passing to an
UnsafePointer parameter worked before (passed a pointer to a contiguous
block of 16 floats), now it's making a copy of just the first tuple element,
and passing a smaller memory block. I think I'm interpreting these results
correctly like that.
> On
I've got Swift code wrapping a C API. One of the C structs the API uses looks
like this:
typedef struct {
size_t size;
float transformation[16];
float projection[16];
uint32_t width;
uint32_t height;
} image_info_t;
In Swift, the two array members are 16-tuples of floats.