Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Utilizing C++ in iOS and Mac OS X applications

I'm somewhat moderate in my C++ knowledge but know next to nothing regarding Objective-C. I am planning (and even starting to) learn Objective-C so I can attempt to write a few iOS and even Mac OS X applications but I'm very curious about something I haven't been able to find yet.

Is it possible to write an iOS and / or a Mac OS X application entirely with C++ including the UI components? If it isn't possible to do it entirely in C++ then to what degree is it possible to use mostly C++?

I haven't seen any examples that demonstrate either of these items. I am planning on writing a few mobile applications for iOS and Android and, where possible, I'd like to contain most of my logic inside of C++ code for maximum portability. I already know I can do this but I am unsure of the degree.

like image 898
Kris Avatar asked Jan 06 '12 14:01

Kris


People also ask

Can you make iOS apps with C?

About XCode, Swift, and Objective-CApple's IDE (Integrated Development Environment) for both Mac and iOS apps is XCode, available only to run on macOS. This is the only go-to graphical interface you'll use to write iOS apps. It houses everything you'll need to write code for iOS.

Can you program with C on Mac?

To run the C program in MacOS we need a code editor and code compiler. The Code editor is used to write source code while the code compiler converts the source code into executable files. To write the source code Microsoft Visual Studio Code is used while to convert it into executable files we use command-line tools.

Does MacOS have C compiler?

Various compilers are available in Mac to compile C code. Mac C compilers compile C code into an executable. This executable can be run directly to run the C code. Clang and GCC(GNU Compiler Collection) are the common compilers that are used to compile C code.

Can you still use Objective-C for iOS?

Objective-C is so pervasive in iOS that it's impossible to completely remove it. Apple continues to maintain libraries written in Objective-C, so we should expect Objective-C to be treated as a (mostly) first class language in iOS. At other companies, legacy code remains.


2 Answers

Short answer, yes.

For pure C++, you should take a look at the QT framework.
Otherwise, you'll have hard time for the UI part.

But also remember that Objective-C can be mixed with C++.
That's called Objective-C++ (.mm files).

You can then write code that mix C++ and Objective-C code. With this, you can have the UI parts in Objective-C (may be better, as it will use the native frameworks for the UI components), and the other things in C++.

If you've decided to learn Objective-C, but still want to code in C++ for some parts, I would recommend this approach, instead of pure C++.

On iOS, this is also the only way. While you can code in C++, you have to use Objective-C for the UI part.

EDIT

Here are a few links to get started with Objective-C++:

  • Strategies for Using C++ in Objective-C Projects
  • From C++ to Objective-C
  • CocoaDev
like image 199
Macmade Avatar answered Oct 08 '22 23:10

Macmade


Look this question

I don't know about Mac OS, but in IOS applications you can use C++ in logic but you have to write user interface on Objective-C.

like image 20
Padavan Avatar answered Oct 08 '22 23:10

Padavan