3 Replies
      Latest reply on Mar 14, 2019 6:58 AM by Hoffman
      a.bogong Level 1 Level 1 (0 points)

        Hello all!

         

        I need to use Objective-C into C++ application is there correct way to use it? I found couple of description in the internet but now any working for me.

        • Re: Implement Objective-C into C++. How?
          john daniel Level 3 Level 3 (380 points)

          Can you re-phrase your question? I don't understand.

           

          Generally, when linking different languages, you have to find some lowest-common denominator. Both Objective-C and C++ speak plain old C, so you can use that. You can also use Objective-C++ but that would only allow your Objective-C code to accept C++.

          • Re: Implement Objective-C into C++. How?
            edford Apple Staff Apple Staff (665 points)

            Objective-C++ is the way to go here. What specifically is not working or are you having trouble with? Can you provide code examples?

             

            The starting point to using Objective-C++ is to use the `.mm` file extension instead of `.m`. as a hint to Xcode that it's an Objective-C++ file, if you haven't discovered that detail yet.

            • Re: Implement Objective-C into C++. How?
              Hoffman Level 1 Level 1 (0 points)

              Are you seeling to move from Objective-C to Objective-C++, or from Objective-C to C++?

               

              If the former...

               

              Some discussions of mixing C to C++ code, and moving from C to C++ code:

              https://isocpp.org/wiki/faq/mixing-c-and-cpp

              https://stackoverflow.com/questions/297122/what-should-i-keep-in-mind-when-porting-from-c-to-c

              http://www.cplusplus.com/forum/articles/21017/

               

              The C to C++ move is a bigger mental and bigger coding shift than is the Objective-C to Objective-C++ part of this effort.

               

              If you don”t need the full capabilities of C++ in existing C code, extern “C” and a few tweaks is often enough to get the code compiling and going. Most existing C code will work, with few or no changes. The dragged-to-C++ code definitely won’t use very much of what C++ code can, but it’ll work.

               

               

              If the latter...

               

              If you’ve going from Objective-C code to C++ code, you’ll be re-writing all of the Objective part of the Objective-C code, and some far smaller part of the C code. This is no sam;l effort, as Objective-C and C++ are quite different.  Depending on the existing code, this can approach or can be a wholesale source code re-write.