Working with C fixed-length arrays is a bit annoying when using the C library from Swift. That's because Swift treats it as a Tuple. Tuple is not Iteratable, so it is difficult to refer to elements. What to do with this?
How to convert Tuples to Arrays with reflection, as described at https://qiita.com/codelynx/items/83f4b3829267d8d25b07. There is no problem. However, reflection is a heavy load on the Compiler and is not the method you want to use aggressively.
var foo_list = func_with_c()
let ptr = UnsafeMutablePointer<Foo>(&foo_list.foo.0)
// "Fixed length"Write the size of. For example, suppose you know that the length is 34.
for i in 0..<34 {
let foo = ptr[i]
print(foo)
}
I'm not happy to use var
, but it's compiler friendly because it doesn't do reflections.
I wonder if I often write like this unless there is a particular reason ..?
Reference: Swift Foundation UUID implement
Recommended Posts