What is Objective-C: Why Should You Learn It?

Last updated on Jul 21,2020 1.7K Views

What is Objective-C: Why Should You Learn It?

Objective-C is a language that was developed on top of normal C language. It is a general-purpose language. It has the additional features of Small Talk programming language that makes it an object-oriented programming language. In this article we will be exploring what is Objective-C in detail.

Table of Content

Following Pointers will be covered in this article,

  • Foundation Framework
  • Features Of Objective-C
  • Structure Of Objective-C

So let us get started then,

What is Objective-C?

The Objective-C languages completely support the object-oriented approach. It supports all features of the object-oriented approach like,

  • Encapsulation
  • Data Hiding
  • Inheritance
  • Polymorphism

Example Code

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}

Output

Objective C example code

Explanation

We import the foundation header files which hold the basic functions. With Xcode 5, we can import the Foundation framework as,

@import Foundation;

The main function with an integer return type is declared. The Auto release pool is created to manage the memory in the program. Finally, the Nlog function is used to print statements in Objective-C. “Hello world” is printed here.

Files are stored with .m extension.

Moving on with this What is Objective-C article,

Foundation Framework

Foundation Framework provides many features. Some of these features are listed here,

  • Several extended datatypes like NSArray, NSDictionary, NSSet and so on are included in this framework.
  • A huge set of functions that manipulate files, strings, etc are included in this framework.
  • Features for URL handling, utilities like date formatting, data handling, error handling, etc are provided by this framework.

Moving on with this What is Objective-C article,

Features Of Objective-C

  • It is great for memory management
  • Provides better support for binary frameworks
  • Interoperability with both C++ and Objective C++
  • Many third-party libraries help in the development

Moving on with this What is Objective-C article,

Structure Of Objective-C

The Objective-C Program is divided into seven parts,

  • Pre-processor Commands
  • Interface
  • Implementation
  • Method
  • Variables
  • Statements & Expressions
  • Comments

Example Code

#import Foundation.h;//pre-processor commands
@interface SampleClass:NSObject//interface
(void)sampleMethod;
@end
@implementation SampleClass//implementation
-(void)sampleMethod
{//methods
NSLog(@"Hello, World! n");
}
@end
int main()
{//main method
/* my first program in Objective-C *///commands
SampleClass *sampleClass = [[SampleClass alloc]init];//statement and expression
[sampleClass sampleMethod];
return 0;
}

Output:

Explanation

The Objective C code is divided into seven layers. First, we have the preprocessor commands which are declaring the header files. Then we have an interface that is declared. This is how the creation of an interface is done. @end marks the end of an interface.

This brings us to the end of this article on what is objective-c?  I hope you found this informative and helpful, stay tuned for more tutorials on similar topics.You may also checkout our training program to get in-depth knowledge on jQuery along with its various applications, you can enroll here for live online training with 24/7 support and lifetime access.Implement the above code with different strings and modifications. Now, we have a good understanding of all key concepts related to the pointer.

Got a question for us? Mention them in the comments section of  this blog and we will get back to you.

Comments
0 Comments

Join the discussion

Browse Categories

Subscribe to our Newsletter, and get personalized recommendations.