简体   繁体   English

使用C ++为iOS开发(带有/不带有Xcode)

[英]Developing for iOS in C++ (with/without Xcode)

What are the methods of developing for iOS with C++ ? 使用C++iOS开发的方法有哪些? I am familiar with using Objective-C++ within Xcode, by selecting Obj-C as my language when creating a new project, but what else is there. 通过创建新项目时选择Obj-C作为我的语言,我对在Xcode中使用Objective-C++很熟悉,但是还有什么呢。 I know there are tools like Xamarin that allow for iOS development in C# , however i'm curious as to what officially supported ways of developing for iOS in C++ there are? 我知道有Xamarin之类的工具可以用C#进行iOS开发,但是我很好奇在C++有哪些官方支持的iOS C++方式? Can an iOS app be written completely in C++ with no Objective-C and compile? 是否可以在没有Objective-C完全用C++编写iOS应用并进行编译?

I have an app that pretty freely intermingles Objective-C (.mm files), Objective-C++ (.m files), and C++ (.cpp) as needed. 我有一个应用程序,可以根据需要自由地混合使用Objective-C(.mm文件),Objective-C ++(。m文件)和C ++(。cpp)。 The C++ code is legacy functionality that implements the heavy lifting of our app and has worked across a number of platforms for 20+ years. C ++代码是旧版功能,可实现我们应用程序的繁重工作,并且已经在多个平台上工作了20多年。 No need to re-implement that. 无需重新实现。

To write a C++ object in XCode, just do it. 要使用XCode编写C ++对象,只需执行此操作即可。 Create .cpp and .h files like you would anywhere else. 像在其他任何地方一样,创建.cpp和.h文件。

When you need to interact with a C++ object from Objective-C, you can either go into the properties of the .m file in XCode and change it to use the Objective-C++ compiler, or (better yet) just name it .mm instead of .m. 当您需要与Objective-C中的C ++对象进行交互时,可以在XCode中进入.m文件的属性,然后将其更改为使用Objective-C ++编译器,或者(更好)将其命名为.mm。的.m。 Then you can include your C++ header files with standard #include statements, create C++ objects with new , delete them with delete , and access members with dot notation and pointer notation just like you would from C++. 然后,你可以包括你的C ++标准头文件#include语句,创建C ++使用对象new ,以删除它们delete ,并用点符号和符号指针++就像你从C将访问的成员。

Objective-C is a lot easier to use when dealing with the UI and system calls. 在处理UI和系统调用时,使用Objective-C更加容易。 It isn't hard to learn. 不难学习。 There are probably ways to access all of those objects and methods from C++, but the gymnastics you would have to do each time might make it easier to simply learn enough Objective-C (or Swift) to do those parts in the language Apple intended. 可能存在从C ++访问所有这些对象和方法的方法,但是您每次必须做的体操操作可能使您更容易学习足够的Objective-C(或Swift)来用Apple想要的语言来完成这些部分。 (Keep in mind that to figure out how to do everything in C++ while looking at sample code and documentation that assumes Objective-C or Swift, you're going to have to master those languages anyway.) (请记住,要了解如何使用C ++进行所有操作,同时查看假定使用Objective-C或Swift的示例代码和文档,则无论如何都必须精通这些语言。)

Yes, you can even go to extreme lengths to avoiding Objective-C, you won't be able to do so completely since UIKit depends on it, but nearly every other framework has a C API. 是的,您甚至可以竭尽全力避免使用Objective-C,因为UIKit依赖于它,所以您将无法完全做到这一点,但是几乎所有其他框架都具有C API。 Take a look at this question and the answer to it How to write iOS app purely in C 看看这个问题及其答案如何仅用C语言编写iOS应用

C is not C++, but the answer will give you a hint on what you can do. C不是C ++,但是答案会提示您可以做什么。 It will involve including the objc runtime, and using objc_msgsend. 它将包括包括objc运行时以及使用objc_msgsend。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM