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 file and the
implementation in a code file. The header files, normally suffixed .h, are similar
to C header files while the implementation (method) files, normally
suffixed .m, can be very similar to C code files.

Objective C Class
•
•

Header / Interface file!
.h extension

•
•

Implementation file!
.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 defined in a header
file.
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 defined 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 defines 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-catchfinally 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
@finally block is called afterwards, regardless of
whether or not an exception occurred.
Exceptions & Errors
“Thank You”

More Related Content

What's hot

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
 
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
 
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

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

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 file and the implementation in a code file. The header files, normally suffixed .h, are similar to C header files while the implementation (method) files, normally suffixed .m, can be very similar to C code files. Objective C Class • • Header / Interface file! .h extension • • Implementation file! .m extension!
  • 7. 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 defined in a header file.
  • 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 defined 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 defines 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-catchfinally 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 @finally block is called afterwards, regardless of whether or not an exception occurred.