Friday, August 24, 2012

Classes In Objective-C


Steps involved in the Creation of a new class in Objective -C
For creating a new class in objective -c, we need to declare an interface and then define its implementation. In Objective -C declaration and Definition  are written in two separate files. The Declaration in the .h file and the implementation in the .m file.  Both declarations and the definition parts use compiler directives. Compiler predicates can be recognize by the  Objective-C complier by seeing the @ symbol.  @interface notify the compiler that it is a  Definition and @implementation will notify the compiler it is a implementation part.

Basic Class Declaration 
Now iam going to create a class with a class name MyClassName as a subclass of MyParentClassName.
In the definition part of interface will be look like this.
 
@interface MyClassName : MyParentClassName {
// Here you can declare the attributes
}
// Here you can declare the Methods
@end
After the interface declaration we need to add the implementation part of the interface.
 
@implementation MyClassName
 
@end
After that we need to add some methods to the class. For that we need to define the method name in @interface declaration[if it is need to access to the externel world. otherwise we can define the method inside the implementation.] Your class interface will look like this
#import "MyClassName.h"
@interface MyClassName : MyParentClassName {
// Here you can declare the attributes
}
-(void)deleteData:(NSString *)param1 parameter:(NSString *)param2;
@end
Ater that we need to write the implementation part of the method in the .m file. It will look like this..
#import "MyClassName.h"
 
@implementation MyClassName
 
// **************************************************************************
 
// Function Name        :   (void)deleteData:(NSString *)param1 parameter:(NSString *)param2
 
// Author Name          :   Parag Kavar
 
// Date of Creation     :   08-08-2012 03:35 PM
 
// Function input Param :   NSString
 
// Return Type          :   void
 
// Date of Modification :   ------
 
// Function Description :    Delete Data
 
// **************************************************************************
 
#pragma mark -
 
#pragma mark deleteData
 
-(void)deleteData:(NSString *)param1 parameter:(NSString *)param2{
 
// implement the functionality of the method here 
}
@end
stay tuned… will be back with a new lesson ……
Share with your friends !

No comments:

Post a Comment