Search code examples
iphoneiosipadobjective-c++

Objective-C++ for iOS development


Is it possible to use Objective-C++ for iOS application (iPhone, iPad, iPod touch) development?

Are there any examples and source code on the Internet?


Solution

  • Using ObjC++ is quite easy. You have to declare source files with extension .mm. It will make compiler treat them as ObjC++. The same with headers: use the .hh extension.

    There is another option: go to target settings and set Compile Sources As to Objective-C++.

    That's all. No additional work is necessary.

    Some notes: if you want to develop a native iOS app, then use Objective C. It will save a lot of time. But in some cases using C++ is more appropriate. E.g. for cross-platform development. So you use only a little bit of Objective C for iPhone or Java for Android just to glue your code with environment. Everything else in C++. I use this for my cross-platform game development.

    Another case is performance: Objective C is principally slower then C++. However it is only noticeable during method calls (in ObjC it is called messaging).