0

I've been working at iOS and some Mac programming for years now, and have started reading the documentation for c++. It interests me to learn how to use c++ in iPhone apps, but all that I've read assumes that you've jumped the precipice of a learning curve that comes with c++ AND ObjC. So, ill start with the basics.

Let's say I have class A, and class A wants to implement a simple function from .cpp file B. I would then Create a .mm file, so class A could mix objC and c++, but my problem is that I have no idea WHERE the c++ code goes... In a regular objC method, I would declare methods inside the .h after the @interface line, but with c++, it's just a mess to me...

But then a harder example. What if I want to display UI elements from a C++ class on the iPhone? I have found little to no blog posts or discussions regarding c++ UI (save those lauding the QT library), and nothing related to iOS UI in c++.

Does anybody have code, or best practices for tightly integrating c++ code into an iOS app?

CodaFi
  • 43,043
  • 8
  • 107
  • 153

2 Answers2

1

I think you have the wrong impression of what objective-C++ is. Objective-C++ just lets your Objective-C code work with C++ and vice versa. It doesn't bridge the two languages or object models, it only supports integration within the same source file.

For example, when using UI elements you would still need to use objective-C classes. However, those classes could then interact with C++ classes in the same implementation file.

ThomasW
  • 16,981
  • 4
  • 79
  • 106
0

C++ classes are usually defined in headers as well, just like Objective-C classes. Then in the source file you'd implement their methods etc.

I recommend a good C++ introduction to get familiar with C++.

What if I want to display UI elements from a C++ class on the iPhone? I have found little to no blog posts or discussions regarding c++ UI

That is because that, while possible, is simply not necessary. As you can mix ObjC and C++ together in ObjC++ source files, you can just use the usual libraries.

Community
  • 1
  • 1
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236