用于iOS开发的Objective-C ++ [英] Objective-C++ for iOS development

查看:107
本文介绍了用于iOS开发的Objective-C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能将Objective-C ++用于iOS应用程序(iPhone,iPad,iPod touch)开发?

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?

推荐答案

使用ObjC ++非常简单。
您必须声明扩展名为.mm的源文件。它将使编译器将它们视为ObjC ++。与标题相同:使用.hh扩展名。

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.

还有另一种选择:转到目标设置并设置编译源代码至Objective-C ++。

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

这就是全部。无需额外的工作。

That's all. No additional work is necessary.

一些注意事项:如果你想开发一个原生iOS应用程序,那么使用Objective C.这将节省大量时间。
但在某些情况下使用C ++更合适。例如。用于跨平台开发。因此,您只需使用一小部分Objective C for iPhone或Java for Android,就可以将代码与环境粘合在一起。 C ++中的其他所有内容。我将它用于我的跨平台游戏开发。

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.

另一种情况是性能:目标C主要比C ++慢。然而,它只在方法调用期间才会被注意到(在ObjC中它被称为消息传递)。

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).

这篇关于用于iOS开发的Objective-C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆