You can use C++ from within Objective-C code using the Objective-C++ GCC front-end. This allows you to mix Objective-C and C++ with some restrictions. If you give your source files a ".mm" extension (instead of ".m" or ".cpp") Xcode will use this Objective-C++ front-end.
One thing to remember is that Objective-C objects in a Objective-C++ file are still just Objective-C objects, not C++ classes. You must alloc/init them as usual; you cannot "new" them. The same is true of C++ objects; they must be created on the stack, or you must use "new" to create them in the heap. You cannot (last I checked) embed C++ objects inside an Objective-C object directly; although you can include pointers to C++ objects in your Objective-C object.
For example, you can't:
Code:
@interface ObjCObject : NSObject
{
CppClass mClass;
}
But you can:
Code:
@interface ObjCObject : NSObject
{
CppClass *mClass;
}
Another way of mixing C++ and Objective-C is to wrap your C++ code in C bindings. Your C++ code lives in a ".cpp" file, and your Objective-C object lives in a ".m" file. Your C++ header file would only include C functions (i.e., using the "extern "C" {} " directive) implemented in the C++ file. This is kind of tedious because you have to maintain two interfaces for your C++ objects; the public C interface and the private C++ interface. You also lose some of the benefits of C++ at the API level (polymorphism, inheritance) although you also protect yourself against other problems (fragile base-classes, etc.).
Which path you choose will depend entirely on your situation.
A quick Google search turned up an online tutorial for using Objective-C++ in Xcode. I haven't looked it over in detail, but it's probably a good place to start looking.