SlideShare a Scribd company logo
1 of 31
Download to read offline
iOS Application Development

Objective C

Ashiq Uz Zoha (Ayon),!
ashiq.ayon@gmail.com,!
Dhrubok Infotech Services Ltd.
Introduction
❖

Objective-C is a general-purpose, object-oriented
programming language that adds Smalltalk-style
messaging to the C programming language.!

❖

It is the main programming language used by Apple for
the OS X and iOS operating systems and their respective
APIs, Cocoa and Cocoa Touch.!

❖

Originally developed in the early 1980s, it was selected
as the main language used by NeXT for its NeXTSTEP
operating system, from which OS X and iOS are derived.
Introduction

❖

Objective-C was created primarily by Brad Cox and
Tom Love in the early 1980s at their company Stepstone.!

❖

Uses power of C and features of SmallTalk. We’ll see
later.
Syntax

❖

Objective C syntax is completely different that we have
used so far in the programming languages we know.
Let’s have a look…
Message
❖

Objective C objects sends messages to another object.
It’s similar to calling a method in our known language
like C++ and Java .!
obj->method(argument); // C++!
obj.method(argument); // java
[obj method:argument] ; // Objective C

Object / Instance

Name of Method

Parameters
Interfaces and implementations
❖

Objective-C requires that the interface and implementation of a class be in
separately declared code blocks. !

❖

By convention, developers place the interface in a header le and the
implementation in a code le. The header les, normally sufxed .h, are similar
to C header les while the implementation (method) les, normally
sufxed .m, can be very similar to C code les.

Objective C Class
•
•

Header / Interface le!
.h extension

•
•

Implementation le!
.m extension!
Interface
❖

NOT “User Interface” or “Interface of OOP in Java” :)!

❖

In other programming languages, this is called a "class
definition”.!

❖

The interface of a class is usually dened in a header
le.
Interface
Implementation
Object Creation

Pointer
:-D

Allocate

MyClass *objectName = [[MyClass alloc] init] ;
Initialize
Methods
❖

Method is declared in objective C as follows!

•

Declaration : !
- (returnType) methodName:(typeName) variable1 :
(typeName)variable2;!

•

Example : !
-(void) calculateAreaForRectangleWithLength:(CGfloat) length ;!

•

Calling the method: !
[self calculateAreaForRectangleWithLength:30];
Class Method
❖

Class methods can be accessed directly without creating
objects for the class. They don't have any variables and
objects associated with it.!

❖

Example :!

•

+(void)simpleClassMethod;!

❖

It can be accessed by using the class name (let's assume
the class name as MyClass) as follows.!

•

[MyClass simpleClassMethod];
Class Method
Sounds Familiar ?!
❖

Can we remember something like “Static
Method” ? !

•

public static void MethodName(){}!

•

Classname.MethodName() ; // static method!

•

[ClassName MethodName]; // class method
Instance methods
❖

Instance methods can be accessed only after creating an
object for the class. Memory is allocated to the instance
variables.!

❖

Example :!

•

-(void)simpleInstanceMethod; !

❖

Accessing the method :!
MyClass *objectName = [[MyClass alloc]init] ;!
[objectName simpleInstanceMethod];
Property
❖

For an external class to access class variables properties
are used.!

❖

Example: @property(nonatomic , strong) NSString
*myString;!

❖

You can use dot operator to access properties. To access
the above property we will do the following.!

❖

self.myString = @“Test"; or [self setMyString:@"Test"];
Memory Management
❖

Memory management is the programming discipline of
managing the life cycles of objects and freeing them
when they are no longer needed.!

❖

Memory management in a Cocoa application that
doesn’t use garbage collection is based on a reference
counting model.!

❖

When you create or copy an object, its retain count is 1.
Thereafter other objects may express an ownership
interest in your object, which increments its retain count.
Memory Management Rules
•

You own any object you create by allocating memory for it or copying it. !

!

mutableCopy,

Related methods: alloc, allocWithZone:, copy, copyWithZone:, !
mutableCopyWithZone:!
•

!
•

!
•

If you are not the creator of an object, but want to ensure it stays in memory for you
to use, you can express an ownership interest in it.!
Related method: retain!
If you own an object, either by creating it or expressing an ownership interest, you are
responsible for releasing it when you no longer need it.!
Related methods: release, autorelease!
Conversely, if you are not the creator of an object and have not expressed an
ownership interest, you must not release it.
Reference Counting System
❖

object-ownership scheme is implemented through a
reference-counting system that internally tracks how
many owners each object has. When you claim
ownership of an object, you increase it’s reference count,
and when you’re done with the object, you decrease its
reference count.!

❖

While its reference count is greater than zero, an object
is guaranteed to exist, but as soon as the count reaches
zero, the operating system is allowed to destroy it.
•

In the past, developers manually controlled an object’s
reference count by calling special memory-management
methods dened by the NSObject protocol. This is called
Manual Retain Release (MRR). !
!

•

In a Manual Retain Release environment, it’s your job to claim
and relinquish ownership of every object in your program. You
do this by calling special memory-related methods,
MRR
alloc

Create an object and
claim ownership of it.

retain

Claim ownership of an
existing object.

copy

Copy an object and
claim ownership of it.

release

Relinquish ownership of
an object and destroy it
immediately.

autorelease

Relinquish ownership of
an object but defer its
destruction.
We don’t need them Now :)
Automatic Reference Counting
❖

Automatic Reference Counting works the exact same
way as MRR, but it automatically inserts the
appropriate memory-management methods for you.!

❖

This is a big deal for Objective-C developers, as it lets
them focus entirely on what their application needs to
do rather than how it does it.
Constructors , Destructors
❖

Constructor in objective C is technically just “init” method.!

❖

Default constructor for every object is !

-(id) init { !
!

!

!

!

self = [super init] ; !

!

!

!

!

return self ; !

!

!

!

}!

❖

Like Java , Objective C has only parent class , i,e NSObject. So, we
access constructor of super class by [super init];
Protocols
❖

A protocol is a group of related properties and methods that can
be implemented by any class.!

❖

They are more flexible than a normal class interface, since they let
you reuse a single API declaration in completely unrelated classes.!
Protocol Definition
❖

Here is an example of a protocol which includes one method, notice
the instance variable delegate is of type id, as it will be unknown at
compile time the type of class that will adopt this protocol.
Adopting the Protocol
❖

To keep the example short, I am using the application
delegate as the class that adopts the protocol. Here is how
the app delegate looks:
Blocks
❖

An Objective-C class denes an object that combines data with
related behaviour. Sometimes, it makes sense just to represent a
single task or unit of behaviour, rather than a collection of
methods.!

❖

Blocks are a language-level feature added to C, Objective-C and
C++, which allow you to create distinct segments of code that
can be passed around to methods or functions as if they were
values.!

❖

Blocks are Objective-C objects, which means they can be added
to collections like NSArray or NSDictionary.
Blocks
Exceptions & Errors
❖

Exceptions can be handled using the standard try-catchnally pattern found in most other high-level
programming languages. First, you need to place any
code that might result in an exception in an @try block.
Then, if an exception is thrown, the corresponding
@catch() block is executed to handle the problem. The
@nally block is called afterwards, regardless of
whether or not an exception occurred.
Exceptions & Errors
“Thank You”

More Related Content

What's hot

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building BlocksCate Huston
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART IHari Christian
 
Core java lessons
Core java lessonsCore java lessons
Core java lessonsvivek shah
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and GithubJo Erik San Jose
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAbhishekMondal42
 
OOPs Concepts - Android Programming
OOPs Concepts - Android ProgrammingOOPs Concepts - Android Programming
OOPs Concepts - Android ProgrammingPurvik Rana
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabsbrainsmartlabsedu
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)dannygriff1
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developersAndrei Rinea
 
Java principles
Java principlesJava principles
Java principlesAdel Jaffan
 
Java Basics
Java BasicsJava Basics
Java Basicssunilsahu07
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IVHari Christian
 
Core java Basics
Core java BasicsCore java Basics
Core java BasicsRAMU KOLLI
 
OOP programming
OOP programmingOOP programming
OOP programminganhdbh
 

What's hot (20)

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Intro to OOP PHP and Github
Intro to OOP PHP and GithubIntro to OOP PHP and Github
Intro to OOP PHP and Github
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java
JavaJava
Java
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
OOPs Concepts - Android Programming
OOPs Concepts - Android ProgrammingOOPs Concepts - Android Programming
OOPs Concepts - Android Programming
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
 
Core Java
Core JavaCore Java
Core Java
 
core java course online
core java course onlinecore java course online
core java course online
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
 
Java principles
Java principlesJava principles
Java principles
 
Java Basics
Java BasicsJava Basics
Java Basics
 
04 Java Language And OOP Part IV
04 Java Language And OOP Part IV04 Java Language And OOP Part IV
04 Java Language And OOP Part IV
 
Core java Basics
Core java BasicsCore java Basics
Core java Basics
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
OOP programming
OOP programmingOOP programming
OOP programming
 

Viewers also liked

Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cMayank Jalotra
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
iPhone Programming [1/17] : Objective-C
iPhone Programming [1/17] : Objective-CiPhone Programming [1/17] : Objective-C
iPhone Programming [1/17] : Objective-CIMC Institute
 
Objective-C: a gentle introduction
Objective-C: a gentle introductionObjective-C: a gentle introduction
Objective-C: a gentle introductionGabriele Petronella
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof languagenicky_walters
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective csagaroceanic11
 
I Phone Development Presentation
I Phone Development PresentationI Phone Development Presentation
I Phone Development PresentationAessam
 
Objective-C for Beginners
Objective-C for BeginnersObjective-C for Beginners
Objective-C for BeginnersAdam Musial-Bright
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CAsim Rais Siddiqui
 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective cKenny Nguyen
 
Hybrid vs Native Mobile App. Decide in 5 minutes!
Hybrid vs Native Mobile App. Decide in 5 minutes!Hybrid vs Native Mobile App. Decide in 5 minutes!
Hybrid vs Native Mobile App. Decide in 5 minutes!July Systems
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CJussi Pohjolainen
 
High Level Languages (Imperative, Object Orientated, Declarative)
High Level Languages (Imperative, Object Orientated, Declarative)High Level Languages (Imperative, Object Orientated, Declarative)
High Level Languages (Imperative, Object Orientated, Declarative)Project Student
 
Object-Orientated Design
Object-Orientated DesignObject-Orientated Design
Object-Orientated DesignDamian T. Gordon
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptReact Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptKobkrit Viriyayudhakorn
 
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)Project Student
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignHaitham El-Ghareeb
 

Viewers also liked (20)

Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
iPhone Programming [1/17] : Objective-C
iPhone Programming [1/17] : Objective-CiPhone Programming [1/17] : Objective-C
iPhone Programming [1/17] : Objective-C
 
Objective-C: a gentle introduction
Objective-C: a gentle introductionObjective-C: a gentle introduction
Objective-C: a gentle introduction
 
Ndu06 typesof language
Ndu06 typesof languageNdu06 typesof language
Ndu06 typesof language
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
I Phone Development Presentation
I Phone Development PresentationI Phone Development Presentation
I Phone Development Presentation
 
Objective-C for Beginners
Objective-C for BeginnersObjective-C for Beginners
Objective-C for Beginners
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective c
 
Hybrid vs Native Mobile App. Decide in 5 minutes!
Hybrid vs Native Mobile App. Decide in 5 minutes!Hybrid vs Native Mobile App. Decide in 5 minutes!
Hybrid vs Native Mobile App. Decide in 5 minutes!
 
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 Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
High Level Languages (Imperative, Object Orientated, Declarative)
High Level Languages (Imperative, Object Orientated, Declarative)High Level Languages (Imperative, Object Orientated, Declarative)
High Level Languages (Imperative, Object Orientated, Declarative)
 
Object-Orientated Design
Object-Orientated DesignObject-Orientated Design
Object-Orientated Design
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptReact Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
 
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)
Appraisal (Self Assessment, Peer Assessment, 360 Degree Feedback)
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Objective-C
Objective-CObjective-C
Objective-C
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 

Similar to Intro to Objective C

Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Hemlathadhevi Annadhurai
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone DevelopmentThoughtWorks
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csjaved75
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++KAUSHAL KUMAR JHA
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
C++ Introduction brown bag
C++ Introduction brown bagC++ Introduction brown bag
C++ Introduction brown bagJacob Green
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptxAdikhan27
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingMH Abid
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTnikshaikh786
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introductionSireesh K
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Intro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CIntro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CAndrew Rohn
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talkbradringel
 

Similar to Intro to Objective C (20)

Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year cs
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
C++ Introduction brown bag
C++ Introduction brown bagC++ Introduction brown bag
C++ Introduction brown bag
 
oop.pptx
oop.pptxoop.pptx
oop.pptx
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
SE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPTSE-IT JAVA LAB OOP CONCEPT
SE-IT JAVA LAB OOP CONCEPT
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Introduction to c ++ part -1
Introduction to c ++   part -1Introduction to c ++   part -1
Introduction to c ++ part -1
 
Intro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-CIntro to iOS: Object Oriented Programming and Objective-C
Intro to iOS: Object Oriented Programming and Objective-C
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Objective-C talk
Objective-C talkObjective-C talk
Objective-C talk
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Intro to Objective C

  • 1. iOS Application Development Objective C Ashiq Uz Zoha (Ayon),! ashiq.ayon@gmail.com,! Dhrubok Infotech Services Ltd.
  • 2. Introduction ❖ Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.! ❖ It is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch.! ❖ Originally developed in the early 1980s, it was selected as the main language used by NeXT for its NeXTSTEP operating system, from which OS X and iOS are derived.
  • 3. Introduction ❖ Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s at their company Stepstone.! ❖ Uses power of C and features of SmallTalk. We’ll see later.
  • 4. Syntax ❖ Objective C syntax is completely different that we have used so far in the programming languages we know. Let’s have a look…
  • 5. Message ❖ Objective C objects sends messages to another object. It’s similar to calling a method in our known language like C++ and Java .! obj->method(argument); // C++! obj.method(argument); // java [obj method:argument] ; // Objective C Object / Instance Name of Method Parameters
  • 6. Interfaces and implementations ❖ Objective-C requires that the interface and implementation of a class be in separately declared code blocks. ! ❖ By convention, developers place the interface in a header le and the implementation in a code le. The header les, normally sufxed .h, are similar to C header les while the implementation (method) les, normally sufxed .m, can be very similar to C code les. Objective C Class • • Header / Interface le! .h extension • • Implementation le! .m extension!
  • 7. Interface ❖ NOT “User Interface” or “Interface of OOP in Java” :)! ❖ In other programming languages, this is called a "class denition”.! ❖ The interface of a class is usually dened in a header le.
  • 10. Object Creation Pointer :-D Allocate MyClass *objectName = [[MyClass alloc] init] ; Initialize
  • 11. Methods ❖ Method is declared in objective C as follows! • Declaration : ! - (returnType) methodName:(typeName) variable1 : (typeName)variable2;! • Example : ! -(void) calculateAreaForRectangleWithLength:(CGfloat) length ;! • Calling the method: ! [self calculateAreaForRectangleWithLength:30];
  • 12. Class Method ❖ Class methods can be accessed directly without creating objects for the class. They don't have any variables and objects associated with it.! ❖ Example :! • +(void)simpleClassMethod;! ❖ It can be accessed by using the class name (let's assume the class name as MyClass) as follows.! • [MyClass simpleClassMethod];
  • 13. Class Method Sounds Familiar ?! ❖ Can we remember something like “Static Method” ? ! • public static void MethodName(){}! • Classname.MethodName() ; // static method! • [ClassName MethodName]; // class method
  • 14. Instance methods ❖ Instance methods can be accessed only after creating an object for the class. Memory is allocated to the instance variables.! ❖ Example :! • -(void)simpleInstanceMethod; ! ❖ Accessing the method :! MyClass *objectName = [[MyClass alloc]init] ;! [objectName simpleInstanceMethod];
  • 15. Property ❖ For an external class to access class variables properties are used.! ❖ Example: @property(nonatomic , strong) NSString *myString;! ❖ You can use dot operator to access properties. To access the above property we will do the following.! ❖ self.myString = @“Test"; or [self setMyString:@"Test"];
  • 16. Memory Management ❖ Memory management is the programming discipline of managing the life cycles of objects and freeing them when they are no longer needed.! ❖ Memory management in a Cocoa application that doesn’t use garbage collection is based on a reference counting model.! ❖ When you create or copy an object, its retain count is 1. Thereafter other objects may express an ownership interest in your object, which increments its retain count.
  • 17. Memory Management Rules • You own any object you create by allocating memory for it or copying it. ! ! mutableCopy, Related methods: alloc, allocWithZone:, copy, copyWithZone:, ! mutableCopyWithZone:! • ! • ! • If you are not the creator of an object, but want to ensure it stays in memory for you to use, you can express an ownership interest in it.! Related method: retain! If you own an object, either by creating it or expressing an ownership interest, you are responsible for releasing it when you no longer need it.! Related methods: release, autorelease! Conversely, if you are not the creator of an object and have not expressed an ownership interest, you must not release it.
  • 18. Reference Counting System ❖ object-ownership scheme is implemented through a reference-counting system that internally tracks how many owners each object has. When you claim ownership of an object, you increase it’s reference count, and when you’re done with the object, you decrease its reference count.! ❖ While its reference count is greater than zero, an object is guaranteed to exist, but as soon as the count reaches zero, the operating system is allowed to destroy it.
  • 19. • In the past, developers manually controlled an object’s reference count by calling special memory-management methods dened by the NSObject protocol. This is called Manual Retain Release (MRR). ! ! • In a Manual Retain Release environment, it’s your job to claim and relinquish ownership of every object in your program. You do this by calling special memory-related methods,
  • 20. MRR alloc Create an object and claim ownership of it. retain Claim ownership of an existing object. copy Copy an object and claim ownership of it. release Relinquish ownership of an object and destroy it immediately. autorelease Relinquish ownership of an object but defer its destruction.
  • 21. We don’t need them Now :)
  • 22. Automatic Reference Counting ❖ Automatic Reference Counting works the exact same way as MRR, but it automatically inserts the appropriate memory-management methods for you.! ❖ This is a big deal for Objective-C developers, as it lets them focus entirely on what their application needs to do rather than how it does it.
  • 23. Constructors , Destructors ❖ Constructor in objective C is technically just “init” method.! ❖ Default constructor for every object is ! -(id) init { ! ! ! ! ! self = [super init] ; ! ! ! ! ! return self ; ! ! ! ! }! ❖ Like Java , Objective C has only parent class , i,e NSObject. So, we access constructor of super class by [super init];
  • 24. Protocols ❖ A protocol is a group of related properties and methods that can be implemented by any class.! ❖ They are more flexible than a normal class interface, since they let you reuse a single API declaration in completely unrelated classes.!
  • 25. Protocol Definition ❖ Here is an example of a protocol which includes one method, notice the instance variable delegate is of type id, as it will be unknown at compile time the type of class that will adopt this protocol.
  • 26. Adopting the Protocol ❖ To keep the example short, I am using the application delegate as the class that adopts the protocol. Here is how the app delegate looks:
  • 27. Blocks ❖ An Objective-C class denes an object that combines data with related behaviour. Sometimes, it makes sense just to represent a single task or unit of behaviour, rather than a collection of methods.! ❖ Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values.! ❖ Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary.
  • 29. Exceptions & Errors ❖ Exceptions can be handled using the standard try-catchnally pattern found in most other high-level programming languages. First, you need to place any code that might result in an exception in an @try block. Then, if an exception is thrown, the corresponding @catch() block is executed to handle the problem. The @nally block is called afterwards, regardless of whether or not an exception occurred.