0

I recently bought a Mac, and want to rewrite a few of my programs in Objective-C with Cocoa, but have no experience in either.

What I imagine would be the easiest to start with was some of my OpenGL code in C/C++ (just my classes, macros, and math functions mostly). I read somewhere C++ code can be used in Objective-C++ compilers. Is this true, and if so, how do I include the files?

Also, where can I find good resources on how to maybe start a basic application with Cocoa in Objective-C? The resources for Cocoa seem to be sparse compared to that of Windows and OpenGL, so I am having trouble finding information (free information mind you).

I would appreciate any help at all, also let me know if you think this conversion is a bad idea. Thanks in advance!

  • 2
    Why converting when you can import the C++ code as is? You just have to change your objective-C files that call C++ functionality from `.m` to `.mm` – 101010 May 01 '14 at 19:57
  • Not sure, that's sort of what I'm asking. I can't find any good tutorials or information on this, and I've never used Objective-C (C/C++, C#, Java). If I import the code, how do the function calls work when I call them in Objective-C? Will my macros work the same, or does Objective-C even have a precompiler? How do I tell my compiler the code is Objective-C++ and not Objective-C? Do C++11 features such as lambda expressions work in Objective-C++. Obviously you can't answer all these things, especially without code; I really just need the link to some sort of source that covers these topics. – user3594002 May 01 '14 at 20:04
  • 40two is right, you basically just want to make your project an obj-c++ project, the compiler should work as is (llvm) but you can swap it to gcc in the settings somewhere if you want. you might need to do a little bit of obj-c to get your code going, but it should be quite minimal. being able to run c/c++ within obj-c(++) pretty seemlessly is one of the great features about the language – Fonix May 01 '14 at 20:13

1 Answers1

1

Why converting when you can import the C++ code as is? You just have to change your objective-C files that call C++ functionality from .m to .mm, please check the following link:

http://answers.oreilly.com/topic/631-how-to-get-c-and-objective-c-to-play-nicely-in-xcode/

101010
  • 41,839
  • 11
  • 94
  • 168