Could i see an example in which Swift sets a c function to callback its own function, SwiftAddTwoNumbers?. if C function call_AddTwoNumbers is executed anywhere in the .c file, it will calls back the SwiftAddTwoNumbers.
swift file like viewcontroller:
func SwiftAddTwoNumbers(a: Int, b: Int) {
var sum = a + b
print("Sum:", sum)
}
.c file:
void call_AddTwoNumbers(int i, int j
{
}
I needed to pass a Swift object to C++ and then being able to use it in the callback in Swift again (the object being passed around being a Swift consumer of the parse events). The trick was that when you have a raw pointer in Swift, you can tell Swift that this raw pointer points to an instance of a certain type, so:
Making it a Swift object again when getting it back in the callback:
let consumer = Unmanaged<XMLParseConsumer>.fromOpaque(consumerRef).takeUnretainedValue()
…but maybe there is a better way to do this (I am not sure how reference counting is affected). The C++ binding for Swift got much better in the meantime, I think.
At least you have an example of a callback (in C++).
I would recommend to use a more current version of Swift.