Friday, August 20, 2004

CodingGuidelines : I read the coding guideline for Cocoa. I realized again not to use abbreviate and ambiguity names fot the method and variable.

Cocoa Objective-C Language Sample Code : I am cheking how to use C++ classes with Cocoa using the sample, Cocoa_With_Carbon_or_CPP. I knew that I can put C++ codes directly in Objective-C methods because the Objective-C++ compiler can understand both C++ and Objective-C codes as follows.
- (void)message2:(id)sender

{
int howMany;
NSString *theAnswer;
Foo *myCPlusPlusObj; //A C++ object
//Create and use a new C++ object
myCPlusPlusObj=new Foo();
howMany=myCPlusPlusObj->getVariable();
delete myCPlusPlusObj;
//Here we put together an NSString that contains the value returned by fooGetVariable()
theAnswer=[NSString stringWithFormat:@"Hello, World! When our C++ object is queried, it tells us that the number is %i!",howMany];
//Display an alert message on the screen with the string generated above
NSRunAlertPanel(@"C++ from Obj-C",theAnswer,@"OK",NULL,NULL);
}

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?