Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift vs Objective-C - for reusing C++ code

We have an android application having the critical code written in C++ in JNI library.

We are about to implement iOS version of the same application. The plan is to implement in Objective-c as it's straight forward to integrate C code with it. However, as Swift is picking up, we would like to have suggestion on Swift vs Objective-C keeping in mind that we have to use the existing C++ libraries and any Swift bottlenecks.

like image 789
mesibo Avatar asked Nov 09 '22 05:11

mesibo


1 Answers

The way to reuse C++ code is to write an Objective-C wrapper class, with the header file containing nothing that is C++, but the implementation file written in Objective-C++ (.mm suffix).

An Objective-C class can be used from Swift and from Objective-C, so for a Swift project, it doesn't matter if you have a few Objective-C classes.

There is no way currently to call C++ from Swift directly, and I wouldn't expect it for a while. And if you look at how you call C from Swift, you'll probably decide that you are quite happy with the situation.

like image 168
gnasher729 Avatar answered Nov 14 '22 21:11

gnasher729