I get the following error for the code below: "A C function pointer cannot be formed from a local function that captures context."
Does anyone propose a creative solution to populate x
in this example? I'm stumped. The underlying types for _header
and _int
respectively are UnsafePointer<mach_header>?
and Int
import MachO
class Example {
func test() {
var x: [Int] = []
_dyld_register_func_for_add_image { (_header, _int) in
x.append(_int)
}
}
}
x
is not a static variable?_dyld_register_func_for_add_image
takes a C function as argument. In Swift that are global functions or closure that capture no context. If there were a user pointer parameter then you could use a technique as in stackoverflow.com/a/33262376/1187415, but such a parameter is not available here