SlideShare a Scribd company logo
Introduction to Objective C
Objective C
•  Objective C is a programming language, which is used by Apple for
developing the application for iPhone and Mac Systems.
•  Objective C is very old programming language and it was designed and
developed in 1986. Now Objective C has become popular once again as it is
being used by Apple to develop applications for Mac system and iPhone.
•  Full superset of C language
•  Allows any traditional C code.
•  Adds powerful Object oriented capabilities.
OverView
•  Objective C consists of objects, classes, instance variables,
methods.
•  Built entirely around objects.
•  Objects like Windows, views, buttons, controllers exchange
information with each other, respond to events, pass actions to run a
program.
•  In C we write .c and .h files, here we write .h and .m files.
•  .h are the header files and .m are the source code or implementation
files.
Objective C Language
• 
• 
• 
• 
• 

Keywords
Message
Classes and method declaration
Instance Methods and Class Methods
Constructors

•  User Defined Constructors

•  Categories
•  Protocols
Keywords
Keywords in objective C has a prefix @ appended to them. We will look at the
keywords used for different purposes in this section
Keyword

Definition

@interface

This is used to declare a class/interface

@implementation

This is used to define class/category

@protocol

This is used to declare a protocol
Keywords Cont…
Interface
The declaration of a class interface begins with the compiler directive
@interface and ends with the directive @end.
@interface ClassName : ItsSuperclass
{
instance variable declarations
}
method declarations
@end

the name of the interface file usually has the .h extension typical of header
files.
Keywords Cont…
Implementation
The definition of a class is structured very much like its declaration. It
begins with the @implementation directive and ends with the @end directive
@implementation ClassName : ItsSuperclass
method definitions
@end

The name of the implementation file has the .m extension, indicating that it
contains Objective-C source code.
Keywords cont..
Next are the access modifiers. They decide the visibility/ scope of the instance
variables/methods
Keyword

Definition

@private

The instance variable is accessible only within the class that declares it.

@public

The instance variable is accessible everywhere

@protected

The instance variable is accessible within the class that declares it and within
classes that inherit it.
Keywords Cont…
Other keywords:

Keyword

Description

@class

Declares the names of classes
defined elsewhere.

@”string”

Defines a constant NSString object
in the current module and initializes
the object with the specified string.

@property

Provides additional information
about how the accessor methods
are implemented

@synthesize

Tells the compiler to create the
access or method(s)
Keywords Cont…
Declaring a simple property
@interface MyClass : NSObject {
float value;
}
@property float value;
@end
A property declaration is equivalent to declaring two accessor methods i.e.
-(float)value;
-(void)setValue:(float)newValue;
These methods are not shown in the code but can be overridden.
Keywords Cont…
Synthesizing a property with @synthesize
@implementation MyClass : NSObject
@synthesize value;
@end

When a property is synthesized two accessor methods are generated
i.e.
-(float)value;
-(void)setValue:(float)newValue;
These methods are not shown in the code but they can be overridden.
Keywords Cont…
Self
l 

Self is a keyword which refers to current class.

{
[self setOrigin:someX :someY];
}

In the example above, it would begin with the class of the object receiving
the reposition message.
Keywords Cont…
super
l 

l 

It begins in the superclass of the class that defines the method where
super appears.
Super is a keyword which refers to the parent class.
{
[super init];
}
{
[super dealloc];
}

In the example above, it would begin with the superclass of the class
where reposition is defined.
Message
•  It’s the most important extension to C
•  Message is sent when one object asks another to perform a specific action.
•  Equivalent to procedural call in C
•  Simple message call looks like [receiver action], here we are asking the

.

receiver to perform the action

•  Receiver can be a object or any expression that evaluates to an object.
•  Action is the name of the method + any arguments passed to it.
Message with Arguments
•  Sometimes we pass one or more arguments along with the action to the
receiver.
•  We add a argument by adding a colon and the argument after the action like
[receiver action: argument]
•  Real world example of this is [label setText:@”This is my button”];
•  String in Objective C is defined as @””;
•  Multiple arguments can be passed to a action like this
[receiver withAction1:argument1 withacction2:argument2];
For example:
[button setTitle:@”OK” forState:NO];
Classes and Method Declaration
•  Class in objective C is a combination of two files ie .h and .m
•  .h file contains the interface of the class.
•  .m contains the implementation

Class Definition
.h file

.m file

@interface

@implementation

Variable and methods
declaration

Method definitions
Classes and Method Declaration
•  Example of a Person class.
•  Here we define the interface and implementation in Person.h and Person.m
file respectively
Person.h file
#import<Foundation/NSObject.h>

@interface Person: NSObject
{
NSString *name;
}
-(void) setName: (NSString *)str;
+(void) printCompanyName;
@end
Classes and Method Declaration
• 

Now the contents of Person.m file

• 

#import Person.h
@implementation Person
-(void) setName: (NSString *) str
{
name=str;
}
+(void) printCompanyName
{
printf(“This is class method”);
}
@end;
Here we have defined a Class Person which has a instance variable “name” and
a method “setName”.
Classes and Method Declaration
•  Using the Person class
#import<stdio.h>
#import “Person.m"
int main()
{
Person *c = [[Person alloc] init]; // Allocating and initializing Person
[c setName : @”Rahul”]; // Setting Name of the allocated person
[Person printCompanyName] // calls class method
[c release]; // releasing the person object created
return 1; // return
}
Instance and Class Methods
•  In objective C we can define methods at two levels ie Class Level and
Instance level
•  In previous Example we declared a method with a – sign prefixed. That was
a instance level method.
•  If we put + instead of – then we get a class level method.
•  A instance method can be called by the instances of the class. But a class
level can be called without creating any instance.
•  Example to call a instance method;
Person *p=[[Person alloc] init];
[p setName:@”Sunil”];
•  Example to call class method
[Person printCompanyName];
Creating multi parameter method
Objective-C enables programmer to use method with multiple
parameter. These parameter can be of same type or of different
type.
MyClass.h

MyClass.m

#import<Foundation/NSObject.h>

#import<stdio.h>
#import"MyClass.h"

@interface MyClass:NSObject{
}
// declare method for more than one
parameter
-(int) sum: (int) a andb: (int) b andc:
(int)c;
@end

@implementation MyClass
-(int) sum: (int) a andb: (int) b andc:
(int)c;{
return a+b+c;
}
@end
Creating multi parameter method
Objective-C enables programmer to use method with multiple
parameter. These parameter can be of same type or of different
type.
main.m
#import"MyClass.m"
int main()
{
MyClass *class = [[MyClass alloc]init];
NSLog(@"Sum is : %d",[class sum : 5 andb : 6 andc:10]);
[class release];
return ;
}
Output:
Sum is: 21
Constructors
•  When a class is instantiated a constructor is called which is used to initialize
the object properties
•  When a constructor is called it returns an object of a class.
•  If a user does not provide a constructor for a class the default one is used.
•  The default constructor is
-(id) init;
id is a special keyword in Objective C which can be used to refer to any
object.
•  Remember in our Person class example while instantiating the Person class
we called the constructor.
[[Person alloc] init];
It returns a person object.
Categories
•  Typically when a programmer wants to extend the functionality of a
class, he subclasses it and adds methods to it.
•  Categories can be used to add method to a class without
subclassing.
•  Here’s how you create a category
@interface PersonCategory (personcat)
@implementation PersonCategory (personcat)
Categories
• 
• 
• 

Implementation of category.
personcat.h file contains
#import “Person.h"
@interface Person (personcat)
-(void) updateName: (NSString *) str;
@end
personcat.m file contains
#import “personcat.h ”

@implementation Person (personcat)
-(void) updateName: (int)value{
Printf(“%d”,value);
}
@end
The updateName name method now behaves as if it’s the part of Person Class.
Protocols
•  Protocols are like interfaces in Java
•  It declares a set of methods, listing their arguments and return types
•  Now a class can state that its using a protocol in @interface statements in .h
file
•  For example
@interface Person:NSObject <human>
Here human is a protocol.
•  Defining a protocol
@protocol human <NSObject>
-(void) eat;
@end
Keywords Cont…
•  Memory management keywords
Keyword

Description

Alloc

Allocates memory for an object

Retain

Retains a object

Releae

Releases memory of an object

Auto release

Auto release memory used by an object
Memory Management
•  In objective C a programmer has to manage memory ie allocate and
deallocate memory for objects.
•  While instantiating a person object we allocated the memory for the object
by this call.
Person *p=[[Person alloc] init];
•  We have to release whatever objects we create programatically. Memory
management for other objects is taken care of by the Objective C runtime.
•  We use release action to release the unused memory.
The syntax for this is [p release];
Thanks

More Related Content

What's hot

Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
MD Sulaiman
 
javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
SadhanaParameswaran
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
kamalbeydoun
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics Presentation
Sudhakar Sharma
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
PRITI TELMORE
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
Shakib Hasan Sumon
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
Sherwin Banaag Sapin
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
Sourabh Sahu
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
Chetan Gole
 
JAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdfJAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
Prof. Dr. K. Adisesha
 
Java strings
Java   stringsJava   strings
Java strings
Mohammed Sikander
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
Learnbay Datascience
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 

What's hot (20)

Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
OOP java
OOP javaOOP java
OOP java
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Dotnet Basics Presentation
Dotnet Basics PresentationDotnet Basics Presentation
Dotnet Basics Presentation
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
JAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdfJAVA PPT Part-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
 
Java strings
Java   stringsJava   strings
Java strings
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
android layouts
android layoutsandroid layouts
android layouts
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 

Viewers also liked

iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
Eakapong Kattiya
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Dhaval Kaneria
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcodeSunny Shaikh
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
Subhransu Behera
 
Advanced iOS
Advanced iOSAdvanced iOS
Advanced iOS
Pete Goodliffe
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's Dive
Altece
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS Introduction
Pratik Vyas
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
Harry Lovylife
 
Apple iOS
Apple iOSApple iOS
Apple iOS
Chetan Gowda
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 

Viewers also liked (12)

iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
 
iOS Basic
iOS BasiciOS Basic
iOS Basic
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Advanced iOS
Advanced iOSAdvanced iOS
Advanced iOS
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's Dive
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS Introduction
 
Ios operating system
Ios operating systemIos operating system
Ios operating system
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 

Similar to Introduction to objective c

Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4thConnex
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01Zafor Iqbal
 
Objective c
Objective cObjective c
Objective c
ricky_chatur2005
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
kenatmxm
 
C#2
C#2C#2
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
arjun431527
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
ExamRevision_FinalSession_C++ notes.pptx
ExamRevision_FinalSession_C++ notes.pptxExamRevision_FinalSession_C++ notes.pptx
ExamRevision_FinalSession_C++ notes.pptx
nglory326
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
Muhammad Hammad Waseem
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 

Similar to Introduction to objective c (20)

Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
Objective c
Objective cObjective c
Objective c
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
C#2
C#2C#2
C#2
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
My c++
My c++My c++
My c++
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
ExamRevision_FinalSession_C++ notes.pptx
ExamRevision_FinalSession_C++ notes.pptxExamRevision_FinalSession_C++ notes.pptx
ExamRevision_FinalSession_C++ notes.pptx
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 

Recently uploaded

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 

Recently uploaded (20)

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 

Introduction to objective c

  • 2. Objective C •  Objective C is a programming language, which is used by Apple for developing the application for iPhone and Mac Systems. •  Objective C is very old programming language and it was designed and developed in 1986. Now Objective C has become popular once again as it is being used by Apple to develop applications for Mac system and iPhone. •  Full superset of C language •  Allows any traditional C code. •  Adds powerful Object oriented capabilities.
  • 3. OverView •  Objective C consists of objects, classes, instance variables, methods. •  Built entirely around objects. •  Objects like Windows, views, buttons, controllers exchange information with each other, respond to events, pass actions to run a program. •  In C we write .c and .h files, here we write .h and .m files. •  .h are the header files and .m are the source code or implementation files.
  • 4. Objective C Language •  •  •  •  •  Keywords Message Classes and method declaration Instance Methods and Class Methods Constructors •  User Defined Constructors •  Categories •  Protocols
  • 5. Keywords Keywords in objective C has a prefix @ appended to them. We will look at the keywords used for different purposes in this section Keyword Definition @interface This is used to declare a class/interface @implementation This is used to define class/category @protocol This is used to declare a protocol
  • 6. Keywords Cont… Interface The declaration of a class interface begins with the compiler directive @interface and ends with the directive @end. @interface ClassName : ItsSuperclass { instance variable declarations } method declarations @end the name of the interface file usually has the .h extension typical of header files.
  • 7. Keywords Cont… Implementation The definition of a class is structured very much like its declaration. It begins with the @implementation directive and ends with the @end directive @implementation ClassName : ItsSuperclass method definitions @end The name of the implementation file has the .m extension, indicating that it contains Objective-C source code.
  • 8. Keywords cont.. Next are the access modifiers. They decide the visibility/ scope of the instance variables/methods Keyword Definition @private The instance variable is accessible only within the class that declares it. @public The instance variable is accessible everywhere @protected The instance variable is accessible within the class that declares it and within classes that inherit it.
  • 9. Keywords Cont… Other keywords: Keyword Description @class Declares the names of classes defined elsewhere. @”string” Defines a constant NSString object in the current module and initializes the object with the specified string. @property Provides additional information about how the accessor methods are implemented @synthesize Tells the compiler to create the access or method(s)
  • 10. Keywords Cont… Declaring a simple property @interface MyClass : NSObject { float value; } @property float value; @end A property declaration is equivalent to declaring two accessor methods i.e. -(float)value; -(void)setValue:(float)newValue; These methods are not shown in the code but can be overridden.
  • 11. Keywords Cont… Synthesizing a property with @synthesize @implementation MyClass : NSObject @synthesize value; @end When a property is synthesized two accessor methods are generated i.e. -(float)value; -(void)setValue:(float)newValue; These methods are not shown in the code but they can be overridden.
  • 12. Keywords Cont… Self l  Self is a keyword which refers to current class. { [self setOrigin:someX :someY]; } In the example above, it would begin with the class of the object receiving the reposition message.
  • 13. Keywords Cont… super l  l  It begins in the superclass of the class that defines the method where super appears. Super is a keyword which refers to the parent class. { [super init]; } { [super dealloc]; } In the example above, it would begin with the superclass of the class where reposition is defined.
  • 14. Message •  It’s the most important extension to C •  Message is sent when one object asks another to perform a specific action. •  Equivalent to procedural call in C •  Simple message call looks like [receiver action], here we are asking the . receiver to perform the action •  Receiver can be a object or any expression that evaluates to an object. •  Action is the name of the method + any arguments passed to it.
  • 15. Message with Arguments •  Sometimes we pass one or more arguments along with the action to the receiver. •  We add a argument by adding a colon and the argument after the action like [receiver action: argument] •  Real world example of this is [label setText:@”This is my button”]; •  String in Objective C is defined as @””; •  Multiple arguments can be passed to a action like this [receiver withAction1:argument1 withacction2:argument2]; For example: [button setTitle:@”OK” forState:NO];
  • 16. Classes and Method Declaration •  Class in objective C is a combination of two files ie .h and .m •  .h file contains the interface of the class. •  .m contains the implementation Class Definition .h file .m file @interface @implementation Variable and methods declaration Method definitions
  • 17. Classes and Method Declaration •  Example of a Person class. •  Here we define the interface and implementation in Person.h and Person.m file respectively Person.h file #import<Foundation/NSObject.h> @interface Person: NSObject { NSString *name; } -(void) setName: (NSString *)str; +(void) printCompanyName; @end
  • 18. Classes and Method Declaration •  Now the contents of Person.m file •  #import Person.h @implementation Person -(void) setName: (NSString *) str { name=str; } +(void) printCompanyName { printf(“This is class method”); } @end; Here we have defined a Class Person which has a instance variable “name” and a method “setName”.
  • 19. Classes and Method Declaration •  Using the Person class #import<stdio.h> #import “Person.m" int main() { Person *c = [[Person alloc] init]; // Allocating and initializing Person [c setName : @”Rahul”]; // Setting Name of the allocated person [Person printCompanyName] // calls class method [c release]; // releasing the person object created return 1; // return }
  • 20. Instance and Class Methods •  In objective C we can define methods at two levels ie Class Level and Instance level •  In previous Example we declared a method with a – sign prefixed. That was a instance level method. •  If we put + instead of – then we get a class level method. •  A instance method can be called by the instances of the class. But a class level can be called without creating any instance. •  Example to call a instance method; Person *p=[[Person alloc] init]; [p setName:@”Sunil”]; •  Example to call class method [Person printCompanyName];
  • 21. Creating multi parameter method Objective-C enables programmer to use method with multiple parameter. These parameter can be of same type or of different type. MyClass.h MyClass.m #import<Foundation/NSObject.h> #import<stdio.h> #import"MyClass.h" @interface MyClass:NSObject{ } // declare method for more than one parameter -(int) sum: (int) a andb: (int) b andc: (int)c; @end @implementation MyClass -(int) sum: (int) a andb: (int) b andc: (int)c;{ return a+b+c; } @end
  • 22. Creating multi parameter method Objective-C enables programmer to use method with multiple parameter. These parameter can be of same type or of different type. main.m #import"MyClass.m" int main() { MyClass *class = [[MyClass alloc]init]; NSLog(@"Sum is : %d",[class sum : 5 andb : 6 andc:10]); [class release]; return ; } Output: Sum is: 21
  • 23. Constructors •  When a class is instantiated a constructor is called which is used to initialize the object properties •  When a constructor is called it returns an object of a class. •  If a user does not provide a constructor for a class the default one is used. •  The default constructor is -(id) init; id is a special keyword in Objective C which can be used to refer to any object. •  Remember in our Person class example while instantiating the Person class we called the constructor. [[Person alloc] init]; It returns a person object.
  • 24. Categories •  Typically when a programmer wants to extend the functionality of a class, he subclasses it and adds methods to it. •  Categories can be used to add method to a class without subclassing. •  Here’s how you create a category @interface PersonCategory (personcat) @implementation PersonCategory (personcat)
  • 25. Categories •  •  •  Implementation of category. personcat.h file contains #import “Person.h" @interface Person (personcat) -(void) updateName: (NSString *) str; @end personcat.m file contains #import “personcat.h ” @implementation Person (personcat) -(void) updateName: (int)value{ Printf(“%d”,value); } @end The updateName name method now behaves as if it’s the part of Person Class.
  • 26. Protocols •  Protocols are like interfaces in Java •  It declares a set of methods, listing their arguments and return types •  Now a class can state that its using a protocol in @interface statements in .h file •  For example @interface Person:NSObject <human> Here human is a protocol. •  Defining a protocol @protocol human <NSObject> -(void) eat; @end
  • 27. Keywords Cont… •  Memory management keywords Keyword Description Alloc Allocates memory for an object Retain Retains a object Releae Releases memory of an object Auto release Auto release memory used by an object
  • 28. Memory Management •  In objective C a programmer has to manage memory ie allocate and deallocate memory for objects. •  While instantiating a person object we allocated the memory for the object by this call. Person *p=[[Person alloc] init]; •  We have to release whatever objects we create programatically. Memory management for other objects is taken care of by the Objective C runtime. •  We use release action to release the unused memory. The syntax for this is [p release];