Array to Tuple in Swift
Today I had to do something that looks like this, so I am posting my answer in case someone needs this.
I needed to create a C struct for passing to pulseaudio in linux, the struct is like this:

struct pa_cvolume{
    uint32 channels;
    uint32 values[32];
}


what I was trying to do was to set newVolume in as much fields as the value of channels was:

let newVolume = 23123 // some random value

var paVolume = pa_cvolume() // create struct
paVolume.channels = 2 // read channels from other place

var volumeChannels = withUnsafeMutablePointer(&amp;paVolume.values) {
  return UnsafeMutablePointer&lt;UInt32&gt;($0)
}

//iterate as if it was C
for i in 0..&lt;Int(paVolume.channels) {  // Int required to subscript UnsafePointers
  volumeChannels[i] = newVolume
}

print(paVolume)


this way you don't need padding (because creating the struct comes with memory already zeroed)