Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

1458279

Suspended
Original poster
May 1, 2010
1,601
1,521
California
I've been learning ObjC and xCode using Apples training video and they say the new xCode 4.0 fully supports C++.
So can you write an entire iPhone app in C++ and not use any objC?

When they say it's fully supported in xCode, does that mean all the API's are supported, not just making calls but code-completion, etc...?

Thanks, KarlJay.
 
XCode is the IDE. It has always supported many languages including C, Objective-C and C++. Nothing has changed in this respect with XCode 4.

Cocoa and Cocoa Touch are APIs. They are not intrinsically linked to any IDE: you can use Cocoa Touch to write iPhone apps using only command line tools if you really want (no XCode usage). As the APIs are not linked to the IDE there is no change here: Cocoa and Cocoa Touch are still 100% Objective-C APIs.

Now that we have cleared that up it should be very obvious that you still need to use Objective-C.
 
That's kinda strange, during the WWDC 2010 video many people clapped when they said C++ was fully supported. What's the point of supporting C++ when all the APIs require ObjC?

Even if you can write some code in C++, then you'd have a mixed-lang program which could get very confusing.

I don't see the point, until it's a full development option, to use C++.

Why would anyone care that C++ is supported? I could see if it were faster, you could write certain routines that do some heavy work faster than ObjC... otherwise... what's the point?
 
Last edited:
That's kinda strange, during the WWDC 2010 video many people clapped when they said C++ was fully supported. What's the point of supporting C++ when all the APIs require ObjC?

Even if you can write some code in C++, then you'd have a mixed-lang program which could get very confusing.

I don't see the point, until it's a full development option, to use C++.

Why would anyone care that C++ is supported? I could see if it were faster, you could write certain routines that do some heavy work faster than ObjC... otherwise... what's the point?

Well the iOS game I'm developing is pretty much 95% C++, with the exception of code required to interact with the iPhone hardware (touches, starting up the OpenGL view, etc). The reason i'm going this route is for the future possibility of porting the game to other platforms with minimal code changes. I'm also more comfortable with C++ now (although i started programming in Obj C first), especially since an OpenGL-based game does not need much iOS specific code anyway.

But if someone did need to have a really low level application such as a game, audio app, graphics app etc, there are probably situations where you can have certain classes in C or C++ which could improve performance.

The language is fully supported in the IDE, as you could code an entire project in C++. However that doesn't mean you could code an entire Cocoa or Cocoa Touch project in C++.
 
ahhh, ok. So you could (and it sounds like you are), developing in C++ except where you need to access things that are specific to IOS API's.

So the C++ that you are using, how do you tie those into the rest of the program.

In other words, if you write a C++ class, how do you call methods in that class from ObjC?

Say in the game, you have userSwipedLeft, and it needs to call: swipeSwardLeft class. uswerSwipedLeft is ObjC, swipeSwardLeft is C++.

Also are the complier and debugger able to step thru the C++ code and see vars etc...
 
Like robbieduncan stated, there is Objective C++.

Essentially what I have is say.... GameViewController.mm that has the normal UIResponder touch methods... touchesBegan:withEvent, etc, and in those methods I can call a method in my C++ class that handles this:

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	NSArray *touchArray = [touches allObjects];

//PointType is a custom type that holds x,y and z coordinates
	PointType touchPoints[[touchArray count]];
	
	for(int i=0; i<[touchArray count]; i++){
		UITouch *touch = [touchArray objectAtIndex:i];
		
		//Switch x and y coordinates as we're in landscape mode via OpenGL ES
		PointType touchPoint = {[touch locationInView:nil].y, [touch locationInView:nil].x, 0};
		touchPoints[i] = touchPoint;
	}
//sharedGameController is a C++ object
	sharedGameController->handleTouchEvent(TouchTypeBegan, touchPoints, [touchArray count]);
}

the ".mm" extension on that file lets the compiler know you're using Objective-C++ instead of simply Objective-C. So you could have both objC and C++ (and of course C) logic within the same file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.