Introduction to Objective C
Objective-C is a superset of C programming language, which makes C object oriented.
- It was developed by Brad J. Cox at Stepstone Corporation in early 80’s, by adding Smalltalk-80 extensions to C-language.
- It was originally the main language on NextStep OS which was further adopted by Apple.
- It is used by Apple as a primary language to develop applications for MAC system and iPhone.
1.1 Features of Objective-C
Being a derivative of C and Smalltalk, Objective-C comprises many features:
1. It is an object-oriented version of C-language.
2. It is a powerful language which is easy to learn and sophisticated to work with.
3. Better understandability of code.
4. Programmer can use both object oriented and procedural programming strategies as per the requirements.
5. It provides open dynamic binding via Objective-C runtime library which makes it true object oriented.
6. It also uses protocols for implementing multiple-inheritance.
1.2 Creating Objective-C Program
The steps to create your objective-C program on MAC
1 Open Xcode and Choose File > New Project.
2 In the New Project window, choose Application under MAC OS X.
3 Click the Command-Line Tool icon to select it.
4 From the Type drop-down menu, choose Foundation, Click the Choose button.
5 Enter the name of your application and then Select a save location and click the Save button.
6 In the text editor window, open .m file from source folder, and enter the code.
7 Save the file.
8 In Xcode, on the Project window toolbar, click the Build and Run button.
1.3 Sample Example
1.
#import Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@”Programming is fun!”);
[pool drain];
return 0;
}
2.
#import Foundation/foundation.h>
int main( int argc, const char* argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSObject *object = [[NSObject alloc] init];
NSLog(@”Created Object: %@”, object);
[pool release];
return 0;
}
3.
#include <stdio.h>
#import <Foundation/Foundation.h>
int main(void) {
CREATE_AUTORELEASE_POOL(pool);
NSString* aString = @”Uno ,Dos,Tres”;
NSLog(aString);
NSArray *parts = [aString componentsSeparatedByString:@","];
NSString* second = [parts objectAtIndex: 1];
NSLog(second);
return 0;
}


