This is a mirror of official site: http://jasper-net.blogspot.com/

An Overview of Objective-C - Part 1

| Monday, May 9, 2011
I’ve been blogging about our educational iPhone/iPod Touch RPN calculator application called CrunchTime, and so far have given an overview of the platform, talked about the vision of the project, discussed the deployment process of an iPhone application, introduced the Xcode IDE, and outlined the functional specifications of our project.

As I stated before, the main programming language for development on Apple platforms is Objective-C and in a few blog posts I’m going to give a quick overview of the main features of Objective-C that was the main thing I needed to get started with this language for our project. I’m going to use a simplified version of the code that I wrote for the calculation engine of CrunchTime to showcase the features in my examples.

Objective-C is an Object-Oriented programming language that adds a Smalltalk style of messaging to the C programming language. The syntax is a combination of original C syntax combined with Smalltalk message style even though in the newer versions some of the common syntax styles are included to make it easier for C developers to learn, use, and adapt the language.

Like C, you have multiple files for the implementation of a class in Objective-C: a header file that includes the declaration and abstractions of the class with .h extension, and an implementation file with definitions and .m extension. In this part I focus on header files.

The following code is the header file for the CalculationEngine class in CrunchTime named CalculationEngine.h.

#import <Foundation/Foundation.h>
#import "StackManager.h"
 
@interface ComputationEngine : NSObject
{
        StackManager *mgr; 
}
 
// Initialize the stack
-(id) init;
// Calculate the result of an operation by getting the operands from the stack
-(double) calculate: (NSString*) operator;
// Push an operand to the stack
-(void) pushOperand: (double) v;
// Pop an operand from the stack
-(double) popOperand;
// Get a pointer for the stack
-(NSArray*) getStack;
// Get the current size of the stack
-(int) getSize;
// Check to see if stack is empty
-(BOOL) isEmpty;
// Check to see if stack is full
-(BOOL) isFull;
// Clear the stack
-(void) clear;

Read more: .NET Zone

Posted via email from Jasper-net

0 comments: