Using a C ++ library in an Objective-C application?

I am planning on learning Objective-C to write an OS X application, but it will depend on a library written in C ++. Can I interact with C ++ in an Objective-C application? I am new to desktop development.

The C ++ library will be used simply to parse a file and return some data about that file. For example, in the example of compiled libraries in the terminal, you should type

./xlsanalysis my_spreadsheet.xls

      

and it returns:

rows: 34
columns: 10
first row: "My Spreadsheet header"

      

Is it possible to include this library directly in an Objective-C application or interface with it in some way?

+2


source to share


3 answers


Objective-C ++ exists for this purpose, for example. Objective-C plus C ++ (or vice versa). From Objective-C ++ files (like .mm files) you have full access to all C ++ functionality. Be careful when choosing types from C ++ to Objective-C for example. you should convert C ++ string

to NSString

using something like [NSString stringWithCString:cPlusPlusString.c_str()]

. Another direction will be string cPlusPlusString([objectiveCString cString])

(or cStringUsingEncoding:

).



+3


source


Yes, you just need to switch any Obj-C files that contain (directly or indirectly) C ++ content to objective-c ++. Basically it just means changing the extension to .mm

- this will give you the ability to use C ++ and Obj-C together in those files.



+2


source


0


source







All Articles