What differences does it make if I used C++ in Xcode rather than Objective C?

Joined
Jul 9, 2012
Messages
3
Reaction score
0
Points
1
Your Mac's Specs
MacBook Pro with Retina Display, The New iPad 32GB Wifi Only White Version, White iPhone 4S 16GB
I just wanna know the differences when I use C++ rather than Objective C in Xcode? Does it make the app faster and a lot secure or what happens if I use it the other way around?

I know that C++ is way more harder than Objective C but I was just wondering what are the main reasons that I write apps in C++ and not Objective C?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Welcome to Mac-Forums

Let's take a step back and get onto the same ground of discussion before we jump into C++ vs Obj-C. The Mac Cocoa and iOS Cocoa Touch frameworks are written in Objective-C. You NEED to write an Obj-C application to interface to these frameworks. So if you intend to write an application for an iOS device or a Mac, you will have to do it in Obj-C.

Now, here is no reason that you can't write a portion of your application in Obj-C while talking to the framework and use C++ for non-framework related work, this can be confusion especially if you are just beginning to program.

The most common place where I see this happening if in a game or something where you use Obj-C to do all your device/Mac related UI stuff, and then have a physics engine like Box2D which uses C++. You can mix-and-match them without any problems. For that matter, you could even mix-and-match Chipmunk a C-based physics engine.

That being said, you cannot write a purely C++ application and make attempts to use the Apple frameworks, it just doesn't work.

Now as far as fast and secure are concerned. Think about it for a second, the entire framework that runs your Mac or iOS device is based on Obj-C, so writing an application that uses the same language means that it will fit in better, be more secure since you're not finding strange ways to interface to the framework and most likely faster since you aren't "translating" anything across languages..

Having said all that, you will be doing yourself a great favor by sticking with Obj-C if your intention is to write an application for the Mac or iOS device..
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
The only caveat to Razor's otherwise solid advice is that if you don't intend to leverage Apple's frameworks (let's say you want to go cross-platform), you should be fine writing an application for OS X in C++.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,745
Reaction score
2,071
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Vansmith is correct, you could use something like Qt (a cross-platform C++ framework) and write your application entirely in C++. In this case the framework will handle the appropriate calls to the bottom OS, be it Windows, Mac OS or Linux..
 
OP
A
Joined
Jul 9, 2012
Messages
3
Reaction score
0
Points
1
Your Mac's Specs
MacBook Pro with Retina Display, The New iPad 32GB Wifi Only White Version, White iPhone 4S 16GB
That was helpful!
Thank you :)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top