48

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.

Kris
  • 1,789
  • 3
  • 18
  • 27
  • 3
    If you are an intermediate C++ developer, you'll find it very easy and quick to learn Objective-C, which is a much simpler language. Then mix as needed. – Firoze Lafeer Jan 06 '12 at 14:59

5 Answers5

55

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++:

Macmade
  • 52,708
  • 13
  • 106
  • 123
  • Thank you. Are there any articles, books, etc that you recommend for utilizing Objective-C++? It seems like a simple concept to figure out but I also don't want to take it too far in one way or another (basically looking for any best practices or recommendations). – Kris Jan 06 '12 at 15:03
  • 7
    It's worth noting that Qt is obviously not an Apple technology and is not an "official" way of writing Mac apps. Qt apps always feel like a Windows port, and I would caution against using it. – Rob Keniger Jan 06 '12 at 23:24
  • 5
    This is pretty subjective. Many popular apps have been written in Qt including Skype and VLC. Qt simply makes it easy to write cross platform code, it's down to the developer/UX designer to make it "feel right" on the target platform. – donturner Feb 03 '14 at 16:51
  • Thank. What about sdl (instead of Qt)? https://stackoverflow.com/questions/23063659/porting-sdl-app-to-ios – javaLover Mar 29 '19 at 02:14
2

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.

Community
  • 1
  • 1
Padavan
  • 1,056
  • 1
  • 11
  • 32
1

Changes required in build settings to use C++ files in iOS project under "Apple LLVM compiler 4.2 - Language" Option

C++ Language Dialect: Compiler Default C++ Standard Library: Compiler Default

Payal
  • 116
  • 3
1

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 think it is possible to use pure c++ if you want to depend on some 3rd part lib, then yes.

Without that 3rd part lib you have to write all the UI using objective-c the rest you can use c++ as much as you like.

RoundPi
  • 5,819
  • 7
  • 49
  • 75
0

You could use Cocos2d-x engine and write pure C++ for your iOS app, including UI (cocos has basic ui classes like buttons, scroll views, table views, etc - but you need to develop your own Controllers, and Models using various C++ libraries like Hiberlite, or raw SQLite etc)

Cocos has its own interface with iOS/MacOS (a few basic .mm objective-c classes to setup Application run cycle - like app delegate, or runloop and drawing cycle)

So you just write your user code with C++

barney
  • 2,172
  • 1
  • 16
  • 25