Over a million developers have joined DZone.

Cocoa C++ Wrappers

DZone 's Guide to

Cocoa C++ Wrappers

· Mobile Zone ·
Free Resource

So let’s say that you’re looking at developing an iPhone app that needs to share source with Another Platform, so C++ is the logical common ground; but you’d like to keep your iPhone side written the right way, of course. Here’s a helpful post about wrapping std::vector in an NSArray:

Mixing STL, NSArray and Bindings

I am currently writing a crossplatform library that needed to be quick, small and efficient. The library is a parser for a particular file format that I need to work with. The library needs to work on Mac, Windows, and with Java through JNI.

I thought about using Objective-C for the engine and then using GNU-Step or CocoTron but that has a huge overhead and writing the JNI would be a night mare. I didn’t want to write it in straight C, i wanted to use STL’s strings and collection classes and boost’s smart pointers. So C++ it was.

When writing the Objective-C wrapper and test app I wanted to use Cocoa’s bindings mechanism to quickly display the results. The solution was to wrap the classes, very thinly, using an NSArray wrapper around the vector.

In this article we will walk through writing a thin wrapper around a C++ object that parses lines of text out of stores those lines in a vector of strings. The sample project can be downloaded from here

Another interesting bit here:

Hoard: A Nice Abstraction on Cocoa Collections

… Hoard gives you a super simple way to instantiate collections of any sort, containing data of any type, and then “view” that data as one of several available collection types (including both Cocoa and STL collections). You can also instantiate a hoard from any of the included Cocoa or STL collections…

Any libraries, patterns, or snippets to add here that you’ve found useful in constructing C++/Objective-C core functionality engine bits, Dear Readers?


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}