I have C API that I use from Swift.
In Swift, I have:
enum GetSnapshotResult {
case success(snapshot: UIImage, String)
case failure()
}
func getSnapshot(completion: @escaping (GetSnapshotResult) -> Void) {
CAPIGetSnapshot(nil) { (_) in
completion(
.success(
snapshot: UIImage(),
"test"
)
)
}
}
And in C API:
void CAPIGetSnapshot(void * ptr, void(*callbackOnFinish)(void *)) {
//do something in background thread
//and on its finish, call callbackOnFinish from thread
callbackOnFinish(ptr);
}
However, with this I get:
A C function pointer cannot be formed from a closure that captures context
How do I solve this?