I had a trouble to combine c++ and objective-c together in developing a iphone app. I had a 3rd party library to use in the app. I had a plan to use c or c++ to wrap the library and then use objective-c to call it. After I had finished the class with c++, I had a trouble to use it in objective-c. Is there any sample code? Thanks.
in the objective-c head file. I write
#import <UIKit/UIKit.h>
#import "ZJTConstants.h"
#include "TTSAdapter.h"
class Adapter;
@interface ZJTVBlogViewController : UIViewController {
@private
Adapter* adapter;
}
@end
and in the mm file, I write:
if (self) {
adapter = Adapter::getInstance();
// Custom initialization
}
Is it write?
Objective-C is an object-oriented programming language that is a superset of C, as the name of the language might reveal. This means that any valid C program will compile with an Objective-C compiler. It derives all its non-object oriented syntax from C and its object oriented syntax from SmallTalk.
Objective-C is slightly slower than straight C function calls because of the lookups involved in its dynamic nature.
Xcode 4.6. 2 uses the Clang C++ compiler frontend with LLVM as backend which is conform to the C++11 standart and uses libc++ as the standart library.
Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.
In XCode there is a flag to compile all files as Objective-C++. I've used it to compile huge C++ libraries into iOS programs.
If you look at the "Build Settings" there is a place written "Compile Sources As". There is a dropdown menu there where you can select Objective-C++. In the clang/gcc commandline I think it is "-x objective-c++".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With