Recently, I have one problem. The clang can translate Objective-C to c++ use -rewrite-objc.
So I think, the first step. clang compile Objective-C to C++. And then compile only can use c++ compiler. Is it do like this?
clang first translate Objective-C to C++ with runTime, and then compile to the machine code?
-rewrite-objc exists to translate ObjC to C++ so it can be compiled in the Visual Studio. It is still Objective-C semantics and you still need the objective-c runtime. It is not magically converting Objective-C to the C++ OO architecture.
This is much more like when Objective-C was implemented as a pre-compiler extension.
It all relies on the fact that Objective-C classes are just C structures with fancy behavior and objective-c method calls all can be translated to calls to objc_msgSend().
Related
I want to use the openCV2 framework in my iOS app, however, I am more comfortable with swift. I can read and understand obj-c well enough to understand the framework and write the methods I need from it in a bridging header, but I'm not comfortable writing the whole app in obj-C. Unfortunately, there are some data types, (cv::Mat, cv::MserManager, etc) that I will need to use in my datamodel, or possibly elsewhere. Is there a way to include datatypes in my bridging header so that I can work with them in swift?
You cannot use C++ types in code called from Swift. However, you can use them in Objective-C++ files, the ones that have the .mm extension. You can mix Objective-C and C++ code in Objective-C++, and can expose Objective-C methods that don't reference C++ in their declarations to Swift via the bridging wrapper. These functions can still use C++ in their implementations, which are not visible in Swift via the bridging header.
You also need to be careful about the language linkage (remember extern "C"?).
Here are some answers that provide examples:
1) Video processing with OpenCV in IOS Swift project
2) Include C++ header file in Swift
3) How to access Swift-objects from a c++ class?
Unfortunately, you cannot bridge C++ and Objective-C++ directly into Swift. On the bright side, you can still work with the openCV2 framework in your app, but you'll need to write C or Objective-C wrappers for your types as described in a related question here: Can I mix Swift with C++? Like the Objective - C .mm files
I have written a c++ library that needs opencv which is an image processing library. I want to now use this c++ library on ios. To do that I am going to copy my code to a mac and build to produce a cocoa touch static library.
Since, this has a dependency on opencv, I downloaded its ios framework. But now I am confused whether a framework can be used from c++ code or just from objective c/c++ ? Do I have to recompile this library so that i get c++ libraries or I can use the framework in my c++ code?
Yes, it can be used with c++. You will have to make sure you Type is set to "Objective C++ Source" for where you are making the framework calls.
I mix my C++ code with frameworks all the time.
Note this goes both ways. If you have Obj-C interacting with C++, you'll need to either have the file be a .mm or be of the "Objective C++ Source" Type.
The Type selection is in the File Inspector for files.
Objective C can compile C natively. Objective C was built over C. Can swift do the same? If not what are the differences.
Unlike Objective-C, which is a proper superset of C, Swift has been built as an entirely new language. Swift cannot compile C code because the syntax is not compatible.
Swift can interoperate wit C code (see Interacting with C APIs article for more information). However, C code behind the APIs needs to be compiled separately, using a C compiler.
Swift uses swift compiler to parse and then LLVM to optimise and generate code. Hence swift compiler cannot parse C syntax.
As ObjectiveC uses clang compiler(which compiles C, C++, ObjectiveC languages) which generate syntax tree and LLVM for optimisation and code generation. Hence we can use C along with Objective C. So the Clang can parse the C/C++/objective C code, generate syntax tree, do semantic analysis and LLVM does back end compilation.
I couldn't manage to find an answear to this question. Is Swift just an Objective-C wrapper, where Swift code is turned into objective-c when the code compiles?
no, it is made into llvm bytecode or -as pointed out by delnan- as it called today llvm bitcode
"[The new term is used] partly to break association with bytecode as employed by traditional virtual machines (because LLVM IR is very much different from that)"
I am a game developer. I have developed a game using box2d which is in Final Phase. To structure the code when i attempt to make code refactoring i am receiving this error alert http://screencast.com/t/ir1nCvnx . But when i attempt to make code refactoring for another project which is not using .mm suffix means i can make it out. The thing i want to know is can we do code refactoring for the code using c++ concepts. If not what is other way to do code refactoring.
I thought because Xcode depended on the clang front end for all of its
code coverage features, that it would eventually be able to refactor
C++. As I understood it, it didn't refactor C++ in the past because
clang's C++ support was still insufficient.
But clang is a very good C++ compiler now. Yet Xcode still balks at
even renaming symbols (the only refactoring I've ever needed).
So, till now, you can not refactor your C++ code and hope you will get it with new release of clang / LLVM / XCode.