How to use Object C in IOS?
Objective C is used in iOS development. It is built on top of the C programming language and offers object-oriented capabilities and a dynamic runtime. It includes all familiar elements like primitive types i.e. int, float, char, etc. structures, pointers, functions, and control flow constructs.
You can also use standard C library routines which are declared in stdlib.h and stdio.h. In the interface file class is declared and in the implementation file class is defined.
Suppose there is a class IntellipaatClass.h then its interface file is:
@interface IntellipaatClass:NSObject {<br>
// Declaration of class variable<br>
}<br>
// Declaration of class properties<br>
// Declaration of class methods and instance methods<br>
@end<br>
The implementation file IntellipaatClass.m is as follows:
@implementation IntellipaatClass<br>
// Class methods<br>
@end<br>
Methods
In Objective C method is declared as follows –
-(returnType)Method_Name:(type_Name) variable1 :(type_Name)variable2;<br>
Create Object
In Objective C objects are created as follows:
IntellipaatClass *object_Name = [[IntellipaatClass alloc]init] ;<br>

Class methods do not contain any objects and variables related with it. They can be accessed directly without creating objects for the class. Example is as follows:
+(void)Class_Method;<br>
It can be accessed by using the class name like as follows −
[IntellipaatClass ClassMethod];<br>
Instance methods – It can be accessed only after creating an object for the class. Memory is allocated to the instance variables.
-(void)InstanceMethod;<br>
They can be access after creating an object like as follows –
IntellipaatClass *objectName = [[IntellipaatClass alloc]init] ;<br>
[objectName InstanceMethod];<br>
Example
#import <Foundation/Foundation.h><br>
@interface SampleClass:NSObject -(void)sampleMethod;<br>
@end<br>
@implementation SampleClass -(void)sampleMethod{ NSLog(@"Hello, World! n"); }<br>
@end<br>
int main() {<br>
/* my first program in Objective-C */<br>
SampleClass *sampleClass<br>
= [[SampleClassalloc]init];<br>
[sampleClasssampleMethod];<br>
return 0;<br>
}<br>
Objects Communicate Through Messages
In Objective C one object sends a message to another object by calling a method on that object. If you have an object somePerson of class XYZPerson, you can send it the sayHello message like this:
Syntax:
[somePerson sayHello];<br>
