Objective C Features:
Objective C has features include like all other programming languages.These are
1.)Inhritance
2.)Polymorphism
3.)Data Hiding
4.)Exception Handling
5.)Objective C blocks(called Closures in other languages)
Syntax of objective C program:
There are two files in objective c One is Header Files and other is implementation file.
.H Extension:
Header file has extension with name.h and it is also called public API access specifier used file. Anything written here will display to Public.Here is Interface which is public to real world.And this API file also link to public real world.We will discuss complete detail lator.
.m Extension
It is implementation file that is private to the real world.Also It has data hiding capabilities. Anything Declared in it private to real world.
Hello World Program:
#import<foundation/foundation.h>
int main( int argc,const char * argv[])
{
NSAutoreleasepool *pool=[[NSAutorelease alloc]init];
NSLog(@"Hello World");
[pool drain];
return 0;
}
Here Foundation is a master framework of all classes include all cocoa touch and other controls. It include all buttons,sliders display on IOS.
#import <.....> is used to include header files in objective c.
#import "class_file.h" class header file can also be include in such way.
Main is main section of program like all other languages like c where the execution of program is starting.
Then NSAutoreleasePool class is used to allocate memory.
Let it take easy dont be scared after seeming the pool code.
NSAutoreleasePool *pool ----> where *pool is pointer .
In objective c Any variable is created using * Asterisk Sign.
Pointer as you already know it is point to the memory address.
[receiver message]
Don't be scared with message is just method and function like in other programming languages.
Above is the way to send message between the objects.
[[NSAutorelease alloc]init]
It send allocation class message.
General there are two types of message passsing in objective c.
1.)Class Message.
2.)Instance Message
Above can be written as Nested Form You can also Written in simple form like this .
NSAutoreleasePool *pool=[NSAutoreleasePool alloc];
pool=[pool init];
But a good programmer just short the code as it possible.
After that to print it on Console there need a function like
NSLog(@"..");
Here @ is used to write any string in IOS.
[pool drain];
message pass to release all memory providing to string pool.
return 0;
simple you know just return successfull execution of program.
I hope you like my this tutorials. If you have any problem you can comment here and mail me.
Next we will come up with ...
Environment Setup For Objective C
No comments:
Post a Comment