7

I'm thinking about writing an application that will have a web-version and an iPhone version (and perhaps later also an android version).

Since there is some algorithms that are the same on the iPhone and the web versions, I was wondering if it is possible to write that part in c++, while keeping the rest of the application in objective-c?

asked Feb 21, 2011 at 7:26

3 Answers 3

8

Absolutely. You can write in C and C++, as well as Objective-C. Your algorithms can easily be in straight C++.

answered Feb 21, 2011 at 8:06
2
  • 1
    imo you're probably also better off writing the algorithms in c++: suppose you want to reuse them later you won't be tied to objective-c Commented Feb 21, 2011 at 8:17
  • 2
    I was thinking of SO, but according to the P.SE faq, it allows questions on "Architecture", where SO is about "Specific programming problem, software algorithms, coding". I believe that this question falls in the first category. Commented Feb 21, 2011 at 9:21
4

Yes, as others have mentioned you can mix C and C++ in with ObjectiveC. It's worth noting, though, that any code that makes of the Aqua GUI or Cocoa has to rely on Objective-C. So, you could re-use existing business logic in C++ and "wrap" it with Objective-C. I know a number of people have done this with existing game frameworks coded in C++.

answered Feb 21, 2011 at 16:29
1

Yes, you can also write Objective-C++ by changing the file extension from .m to .mm. Then you can mix C++ and Objective-C code in the same file. It makes it very easy for your Objective-C UI code to call your C++ backend code.

answered Jan 3, 2015 at 17:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.