SlideShare a Scribd company logo
1 of 25
Introduction to Objective C
Contents :
ā¦ Language Concepts
ā¦ How Objective C works- Basics
ā¦ Data Types
ā¦ NSInteger
ā¦ NSNumber
ā¦ Operators
ā¦ Loop
ā¦ Inheritance
ā¦ Method Overloading
ā¦ Mutable and Immutable Strings
ā¦ Mutable and Immutable Arrays
ā¦ File Management
What Is Objective C ?
Objective-C is the primary programming language you use when writing
software for OS X and iOS. Itā€™s a superset of the C programming language
and provides object-oriented capabilities and a dynamic runtime.
Objective-C inherits the syntax, primitive types, and flow control
statements of C and adds syntax for defining classes and methods.
Objective-C inherits the syntax, primitive types, and flow control
statements of C and adds syntax for defining classes and methods.
Objective ā€“ C
Characteristics
The class is defined in two different sections
namely @interface and @implementation.
Almost everything is in form of objects.
Objects receive messages and objects are often referred as receivers.
Objects contain instance variables.
Objects and instance variables have scope.
Classes hide an object's implementation.
Properties are used to provide access to class instance variables in
other classes.
Language Concepts:
Fully supports object-oriented programming, including the
four pillars of object-oriented development:
Encapsulation
Data hiding
Inheritance
Polymorphism
Data Encapsulation
Encapsulation is an Object-Oriented Programming concept that
binds together the data and functions that manipulate the data and
that keeps both safe from outside interference and misuse.
Data encapsulation is a mechanism of bundling the data and the
functions that use them.
Inheritance
Inheritance allows us to define a class in terms of another class which
makes it easier to create and maintain an application. This also provides an
opportunity to reuse the code functionality and fast implementation time.
This existing class is called the base class, and the new class is referred to as
the derived class.
Objective-C allows only multilevel inheritance, i.e., it can have only one
base class but allows multilevel inheritance. All classes in Objective-C is
derived from the superclass NSObject.
Program Structure
A Objective-C program basically consists of the following
parts:
Preprocessor Commands
Interface
Implementation
Method
Variables
Statements & Expressions
Comments
Sample Code:
#import <Foundation/Foundation.h>
@interface SampleClass:NSObject
(void)sampleMethod;
@end
@implementation SampleClass
- (void)sampleMethod
{
NSLog(@"Hello, World! n");
}
@end
int main()
{
/* my first program */SampleClass *sampleClass = [[SampleClass alloc]init];
[sampleClass sampleMethod];
return 0;
}
Objective- C Basic Syntax
Tokens in Objective ā€“ C:
Token is either a keyword, an identifier, a constant, a string literal, or a symbol. For
Example:
NSLog(@"Hello, World! nā€);
Semicolons:
The semicolon is a statement terminator. That is, each individual statement
must be ended with a semicolon. It indicates the end of one logical entity. For
Example:
NSLog(@"Hello, World! n");
return 0;
Comments:
Comments are like helping text in your Objective-C program and they are
ignored by the compiler. For example:
/* my first program in Objective-C */
Objective- C Data Types
Data types refer to an extensive system used for declaring variables or
functions of different types. The type of a variable determines how much space
it occupies in storage and how the bit pattern stored is interpreted.
Types And Descriptions:
Basic Types: They are arithmetic types and consist of the two types: (a)
integer types and (b) floating-point types.
Enumerated types: They are again arithmetic types and they are used to
define variables that can only be assigned certain discrete integer values
throughout the program.
The type void: The type specifier void indicates that no value is available.
Derived type: They include (a) Pointer types, (b) Array types, (c) Structure
types, (d) Union types and (e) Function types.
NSInteger & NSNumber
You usually want to use NSInteger when you don't know what kind of processor
architecture your code might run on, so you may for some reason want the largest
possible int type, which on 32 bit systems is just an int, while on a 64-bit system it's
a long.
The NSNumber class is a lightweight, object-oriented wrapper around Cā€™s numeric
primitives. Itā€™s main job is to store and retrieve primitive values, and it comes with
dedicated methods for each data type:
NSNumber *aBool = [NSNumber numberWithBool:NO];
NSNumber *aChar = [NSNumber numberWithChar:'z'];
NSNumber *aUChar = [NSNumber numberWithUnsignedChar:255];
NSLog(@"%@", [aBool boolValue] ? @"YES" : @"NO");
NSLog(@"%c", [aChar charValue]);
Objective-C Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. Objective-C language is rich in
built-in operators and provides following types of operators:
Arithmetic Operators ā€“ (+, -, *, /, %, ++, --)
Relational Operators ā€“ (=, !=, >, <, >=, <= )
Logical Operators ā€“ (&&, ||, ! )
Bitwise Operators ā€“ ( &, |, ^, <<, >>)
Assignment Operators ā€“ (=, +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |= )
Misc Operators ā€“ (sizeof, &, *, ?:)
Objective-C Loops
A loop statement allows us to execute a statement or group of statements
multiple times and following is the general form of a loop statement in
most of the programming languages:
while
for
do while
nested loops
Loop Control Statements:
break statement
control statement
Mutable and Immutable
Strings & Arrays:
A mutable string should be used when you are physically
changing the value of the existing string, without completely
discarding the old value.
Examples might include adding a character to the beginning or the
end, or changing a character in the middle.
NSString has methods such as stringByAppendingString:, which
does add a string to an existing oneā€”but it returns a new string.
A mutable object can be mutated or changed. An immutable object cannot.
For example, while you can add or remove objects from an NSMutableArray,
you cannot do either with an NSArray.
Mutable objects can have elements changed, added to, or removed, which
cannot be achieved with immutable objects. Immutable objects are stuck with
whatever input you gave them in their [[object alloc] initWith...] initializer.
The advantages of your mutable objects is obvious, but they should only be
used when necessary (which is a lot less often than you think) as they take up
more memory than immutable objects.
Mutable objects can be modified, immutable objects can't.
Eg: NSMutableArray has addObject: removeObject: methods (and more), but
NSArray doesn't.
Modifying strings:
NSString *myString = @"hello";
myString = [myString stringByAppendingString:@" world"];
Vs
NSMutableString *myString = @"hello";
[myString appendString:@" worldā€];
ā€¢ Mutable objects are particularly useful when dealing with arrays.
Eg: if you have an NSArray of NSMutableStrings you can do:
[myArray makeObjectsPerformSelector:@selector(appendString:)
withObject:@ā€œ!!!"];
which will add 3 ! to the end of each string in the array.
But if you have an NSArray of NSStrings (therefore immutable), you can't do
this (at least it's a lot harder, and more code, than using NSMutableString)
File Handling In Objective C
File handling is made available with the help of class NSFileManager.
Methods used in File Handling:
The list of the methods used for accessing and manipulating files is listed below.
Here, we have to replace the FilePath1, FilePath2 and FilePath strings to our
required full file paths to get the desired action.
>> Check if file exists at a path:
NSFileManager *fileManager = [NSFileManager defaultManager]; //Get documents directory
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0];
if ([fileManager fileExistsAtPath:@""]==YES)
{
NSLog(@"File exists");
}
Memory Management
It is the process by which the memory of objects are allocated when
they are required and deallocated when they are no longer required.
Managing object memory is a matter of performance; if an
application doesn't free unneeded objects, its memory footprint
grows and performance suffers.
Objective-C Memory management techniques can be broadly
classified into two types:
1."Manual Retain-Release" or MRR
2."Automatic Reference Counting" or ARC
In Automatic Reference Counting or ARC, the system uses the
same reference counting system as MRR, but it inserts the
appropriate memory management method calls for us at compile-
time.
Also, iOS objects never had garbage collection feature. And with
ARC, there is no use of garbage collection in OS-X too.
Objective- C Pointers
Every variable is a memory location and every memory location has its address
defined which can be accessed using ampersand (&) operator, which denotes an
address in memory. Consider the following example, which will print the address of
the variables defined:
What are Pointers?
A pointer is a variable whose value is the address of another variable, i.e., direct
address of the memory location. Like any variable or constant, you must declare a
pointer before you can use it to store any variable address. The general form of a
pointer variable declaration is:
type *var-name;
How to use Pointers?
There are few important operations, which we will do with
the help of pointers very frequently.
(a) we define a pointer variable,
(b) assign the address of a variable to a pointer, and
(c) finally access the value at the address available in the
pointer variable.
Objective-C Methods
Methods represent the actions that an object knows how to perform.
Theyā€™re the logical counterpart to properties, which represent an objectā€™s
data.
You can think of methods as functions that are attached to an object
however, they have a very different syntax.
Naming Conventions:
Objective-C methods are designed to remove all ambiguities from an
API. Three simple rules for naming Objective-C methods:
1.Donā€™t abbreviate anything.
2.Explicitly state parameter names in the method itself.
3.Explicitly describe the return value of the method.
// Car.h
#import <Foundation/Foundation.h>
@interface Car : NSObject
// Accessors ā€“
-(BOOL)isRunning;
- (void)setRunning:(BOOL)running;
- (NSString *)model;
- (void)setModel:(NSString *)model;
// Calculated values
- (double)maximumSpeed;
-(double)maximumSpeedUsingLocale:(NSLocale *)locale;
// Action methods
- (void)startEngine;
- (void)driveForDistance:(double)theDistance;
// Error handling methods
- (BOOL)loadPassenger:(id)aPassenger error:(NSError **)error;
// Constructor methods
- (id)initWithModel:(NSString *)aModel;
- (id)initWithModel:(NSString *)aModel mileage:(double)theMileage;
// Comparison methods
- (BOOL)isEqualToCar:(Car *)anotherCar;
- (Car *)fasterCar:(Car *)anotherCar;
- (Car *)slowerCar:(Car *)anotherCar;
Upcoming Topics:
Introduction to XCode
Introduction to iPhone Architecture
Essential COCOA Touch Classes
Nib File and Story Board
MVC Framework
Intro to .H and .M Files
THANK YOU

More Related Content

What's hot

Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Edureka!
Ā 
C#.NET
C#.NETC#.NET
C#.NETgurchet
Ā 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
Ā 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Edureka!
Ā 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingRajesh Ganesan
Ā 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
Ā 
An introduction to mobile app development and investing
An introduction to mobile app development and investingAn introduction to mobile app development and investing
An introduction to mobile app development and investingBrandon Na
Ā 
Automate using Python
Automate using PythonAutomate using Python
Automate using PythonYogeshIngale9
Ā 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycleSoham Patel
Ā 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
Ā 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
Ā 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
Ā 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajaxPihu Goel
Ā 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-ProgrammersAhmad Alhour
Ā 
django part-1
django part-1django part-1
django part-1Gaurav Dixit
Ā 
Access modifiers in Python
Access modifiers in PythonAccess modifiers in Python
Access modifiers in PythonSantosh Verma
Ā 

What's hot (20)

Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
Ā 
django
djangodjango
django
Ā 
C#.NET
C#.NETC#.NET
C#.NET
Ā 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Ā 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Ā 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Ā 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
Ā 
An introduction to mobile app development and investing
An introduction to mobile app development and investingAn introduction to mobile app development and investing
An introduction to mobile app development and investing
Ā 
Automate using Python
Automate using PythonAutomate using Python
Automate using Python
Ā 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
Ā 
Oops ppt
Oops pptOops ppt
Oops ppt
Ā 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
Ā 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Ā 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Ā 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
Ā 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
Ā 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ā 
django part-1
django part-1django part-1
django part-1
Ā 
Access modifiers in Python
Access modifiers in PythonAccess modifiers in Python
Access modifiers in Python
Ā 
Java Collections
Java  Collections Java  Collections
Java Collections
Ā 

Viewers also liked

Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - CJussi Pohjolainen
Ā 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective CPaolo Quadrani
Ā 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective cKenny Nguyen
Ā 
Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersJoris Verbogt
Ā 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals umesh patil
Ā 
Digital Universitas
Digital UniversitasDigital Universitas
Digital UniversitasGiuseppe Arici
Ā 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightGiuseppe Arici
Ā 
Objective-C @ ITIS
Objective-C @ ITISObjective-C @ ITIS
Objective-C @ ITISGiuseppe Arici
Ā 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference CountingGiuseppe Arici
Ā 
PRESENTATION ON PROJECT REPORT
PRESENTATION ON PROJECT REPORTPRESENTATION ON PROJECT REPORT
PRESENTATION ON PROJECT REPORTDiksha Bhargava
Ā 
Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Giuseppe Arici
Ā 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts246paa
Ā 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective CTiyasi Acharya
Ā 
Swift Introduction
Swift IntroductionSwift Introduction
Swift IntroductionGiuseppe Arici
Ā 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview QuestionsClark Davidson
Ā 

Viewers also liked (20)

Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
Ā 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
Ā 
Iphone programming: Objective c
Iphone programming: Objective cIphone programming: Objective c
Iphone programming: Objective c
Ā 
Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
Ā 
Objective-C
Objective-CObjective-C
Objective-C
Ā 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
Ā 
1-oop java-object
1-oop java-object1-oop java-object
1-oop java-object
Ā 
0-oop java-intro
0-oop java-intro0-oop java-intro
0-oop java-intro
Ā 
GDB Mobile
GDB MobileGDB Mobile
GDB Mobile
Ā 
Digital Universitas
Digital UniversitasDigital Universitas
Digital Universitas
Ā 
Automatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma NightAutomatic Reference Counting @ Pragma Night
Automatic Reference Counting @ Pragma Night
Ā 
Objective-C @ ITIS
Objective-C @ ITISObjective-C @ ITIS
Objective-C @ ITIS
Ā 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
Ā 
PRESENTATION ON PROJECT REPORT
PRESENTATION ON PROJECT REPORTPRESENTATION ON PROJECT REPORT
PRESENTATION ON PROJECT REPORT
Ā 
Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013Auto Layout Under Control @ Pragma conference 2013
Auto Layout Under Control @ Pragma conference 2013
Ā 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
Ā 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective C
Ā 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
Ā 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview Questions
Ā 
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
Ā 

Similar to Objective c slide I

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
Ā 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
Ā 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
Ā 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptxKishoreRedla
Ā 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
Ā 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxKorbanMaheshwari
Ā 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++Mukund Trivedi
Ā 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptxKorbanMaheshwari
Ā 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
Ā 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsShanmuganathan C
Ā 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
Ā 
Technical Interview
Technical InterviewTechnical Interview
Technical Interviewprashant patel
Ā 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
Ā 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)Shoaib Ghachi
Ā 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
Ā 

Similar to Objective c slide I (20)

01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
Ā 
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
Ā 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Ā 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Ā 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
Ā 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
Ā 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
Ā 
C#ppt
C#pptC#ppt
C#ppt
Ā 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptx
Ā 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
Ā 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
Ā 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
Ā 
c#.pptx
c#.pptxc#.pptx
c#.pptx
Ā 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
Ā 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
Ā 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
Ā 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Ā 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
Ā 
C language 3
C language 3C language 3
C language 3
Ā 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
Ā 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
Ā 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
Ā 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhisoniya singh
Ā 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
Ā 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
Ā 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
Ā 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
Ā 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
Ā 
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Ā 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
Ā 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
Ā 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
Ā 
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphSIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphNeo4j
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
Ā 
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your BudgetHyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your BudgetEnjoy Anytime
Ā 
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Patryk Bandurski
Ā 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Ā 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Ā 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
Ā 
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | DelhiFULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY šŸ” 8264348440 šŸ” Call Girls in Diplomatic Enclave | Delhi
Ā 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
Ā 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Ā 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
Ā 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ā 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
Ā 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
Ā 
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 āœ“Call Girls In Kalyan ( Mumbai ) secure service
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Ā 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
Ā 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Ā 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
Ā 
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge GraphSIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
SIEMENS: RAPUNZEL ā€“ A Tale About Knowledge Graph
Ā 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Ā 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
Ā 
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your BudgetHyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad āœØ 7001305949 āœØ Cheap Price Your Budget
Ā 
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Integration and Automation in Practice: CI/CD in MuleĀ Integration and Automat...
Ā 

Objective c slide I

  • 1. Introduction to Objective C Contents : ā¦ Language Concepts ā¦ How Objective C works- Basics ā¦ Data Types ā¦ NSInteger ā¦ NSNumber ā¦ Operators ā¦ Loop ā¦ Inheritance ā¦ Method Overloading ā¦ Mutable and Immutable Strings ā¦ Mutable and Immutable Arrays ā¦ File Management
  • 2. What Is Objective C ? Objective-C is the primary programming language you use when writing software for OS X and iOS. Itā€™s a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods.
  • 3. Objective ā€“ C Characteristics The class is defined in two different sections namely @interface and @implementation. Almost everything is in form of objects. Objects receive messages and objects are often referred as receivers. Objects contain instance variables. Objects and instance variables have scope. Classes hide an object's implementation. Properties are used to provide access to class instance variables in other classes.
  • 4. Language Concepts: Fully supports object-oriented programming, including the four pillars of object-oriented development: Encapsulation Data hiding Inheritance Polymorphism
  • 5. Data Encapsulation Encapsulation is an Object-Oriented Programming concept that binds together the data and functions that manipulate the data and that keeps both safe from outside interference and misuse. Data encapsulation is a mechanism of bundling the data and the functions that use them.
  • 6. Inheritance Inheritance allows us to define a class in terms of another class which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. This existing class is called the base class, and the new class is referred to as the derived class. Objective-C allows only multilevel inheritance, i.e., it can have only one base class but allows multilevel inheritance. All classes in Objective-C is derived from the superclass NSObject.
  • 7. Program Structure A Objective-C program basically consists of the following parts: Preprocessor Commands Interface Implementation Method Variables Statements & Expressions Comments
  • 8. Sample Code: #import <Foundation/Foundation.h> @interface SampleClass:NSObject (void)sampleMethod; @end @implementation SampleClass - (void)sampleMethod { NSLog(@"Hello, World! n"); } @end int main() { /* my first program */SampleClass *sampleClass = [[SampleClass alloc]init]; [sampleClass sampleMethod]; return 0; }
  • 9. Objective- C Basic Syntax Tokens in Objective ā€“ C: Token is either a keyword, an identifier, a constant, a string literal, or a symbol. For Example: NSLog(@"Hello, World! nā€); Semicolons: The semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. For Example: NSLog(@"Hello, World! n"); return 0; Comments: Comments are like helping text in your Objective-C program and they are ignored by the compiler. For example: /* my first program in Objective-C */
  • 10. Objective- C Data Types Data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. Types And Descriptions: Basic Types: They are arithmetic types and consist of the two types: (a) integer types and (b) floating-point types. Enumerated types: They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program. The type void: The type specifier void indicates that no value is available. Derived type: They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
  • 11. NSInteger & NSNumber You usually want to use NSInteger when you don't know what kind of processor architecture your code might run on, so you may for some reason want the largest possible int type, which on 32 bit systems is just an int, while on a 64-bit system it's a long. The NSNumber class is a lightweight, object-oriented wrapper around Cā€™s numeric primitives. Itā€™s main job is to store and retrieve primitive values, and it comes with dedicated methods for each data type: NSNumber *aBool = [NSNumber numberWithBool:NO]; NSNumber *aChar = [NSNumber numberWithChar:'z']; NSNumber *aUChar = [NSNumber numberWithUnsignedChar:255]; NSLog(@"%@", [aBool boolValue] ? @"YES" : @"NO"); NSLog(@"%c", [aChar charValue]);
  • 12. Objective-C Operators An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Objective-C language is rich in built-in operators and provides following types of operators: Arithmetic Operators ā€“ (+, -, *, /, %, ++, --) Relational Operators ā€“ (=, !=, >, <, >=, <= ) Logical Operators ā€“ (&&, ||, ! ) Bitwise Operators ā€“ ( &, |, ^, <<, >>) Assignment Operators ā€“ (=, +=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |= ) Misc Operators ā€“ (sizeof, &, *, ?:)
  • 13. Objective-C Loops A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages: while for do while nested loops Loop Control Statements: break statement control statement
  • 14. Mutable and Immutable Strings & Arrays: A mutable string should be used when you are physically changing the value of the existing string, without completely discarding the old value. Examples might include adding a character to the beginning or the end, or changing a character in the middle. NSString has methods such as stringByAppendingString:, which does add a string to an existing oneā€”but it returns a new string.
  • 15. A mutable object can be mutated or changed. An immutable object cannot. For example, while you can add or remove objects from an NSMutableArray, you cannot do either with an NSArray. Mutable objects can have elements changed, added to, or removed, which cannot be achieved with immutable objects. Immutable objects are stuck with whatever input you gave them in their [[object alloc] initWith...] initializer. The advantages of your mutable objects is obvious, but they should only be used when necessary (which is a lot less often than you think) as they take up more memory than immutable objects.
  • 16. Mutable objects can be modified, immutable objects can't. Eg: NSMutableArray has addObject: removeObject: methods (and more), but NSArray doesn't. Modifying strings: NSString *myString = @"hello"; myString = [myString stringByAppendingString:@" world"]; Vs NSMutableString *myString = @"hello"; [myString appendString:@" worldā€]; ā€¢ Mutable objects are particularly useful when dealing with arrays. Eg: if you have an NSArray of NSMutableStrings you can do: [myArray makeObjectsPerformSelector:@selector(appendString:) withObject:@ā€œ!!!"]; which will add 3 ! to the end of each string in the array. But if you have an NSArray of NSStrings (therefore immutable), you can't do this (at least it's a lot harder, and more code, than using NSMutableString)
  • 17. File Handling In Objective C File handling is made available with the help of class NSFileManager. Methods used in File Handling: The list of the methods used for accessing and manipulating files is listed below. Here, we have to replace the FilePath1, FilePath2 and FilePath strings to our required full file paths to get the desired action. >> Check if file exists at a path: NSFileManager *fileManager = [NSFileManager defaultManager]; //Get documents directory NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [directoryPaths objectAtIndex:0]; if ([fileManager fileExistsAtPath:@""]==YES) { NSLog(@"File exists"); }
  • 18. Memory Management It is the process by which the memory of objects are allocated when they are required and deallocated when they are no longer required. Managing object memory is a matter of performance; if an application doesn't free unneeded objects, its memory footprint grows and performance suffers. Objective-C Memory management techniques can be broadly classified into two types: 1."Manual Retain-Release" or MRR 2."Automatic Reference Counting" or ARC
  • 19. In Automatic Reference Counting or ARC, the system uses the same reference counting system as MRR, but it inserts the appropriate memory management method calls for us at compile- time. Also, iOS objects never had garbage collection feature. And with ARC, there is no use of garbage collection in OS-X too.
  • 20. Objective- C Pointers Every variable is a memory location and every memory location has its address defined which can be accessed using ampersand (&) operator, which denotes an address in memory. Consider the following example, which will print the address of the variables defined: What are Pointers? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address. The general form of a pointer variable declaration is: type *var-name;
  • 21. How to use Pointers? There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable, (b) assign the address of a variable to a pointer, and (c) finally access the value at the address available in the pointer variable.
  • 22. Objective-C Methods Methods represent the actions that an object knows how to perform. Theyā€™re the logical counterpart to properties, which represent an objectā€™s data. You can think of methods as functions that are attached to an object however, they have a very different syntax. Naming Conventions: Objective-C methods are designed to remove all ambiguities from an API. Three simple rules for naming Objective-C methods: 1.Donā€™t abbreviate anything. 2.Explicitly state parameter names in the method itself. 3.Explicitly describe the return value of the method.
  • 23. // Car.h #import <Foundation/Foundation.h> @interface Car : NSObject // Accessors ā€“ -(BOOL)isRunning; - (void)setRunning:(BOOL)running; - (NSString *)model; - (void)setModel:(NSString *)model; // Calculated values - (double)maximumSpeed; -(double)maximumSpeedUsingLocale:(NSLocale *)locale; // Action methods - (void)startEngine; - (void)driveForDistance:(double)theDistance;
  • 24. // Error handling methods - (BOOL)loadPassenger:(id)aPassenger error:(NSError **)error; // Constructor methods - (id)initWithModel:(NSString *)aModel; - (id)initWithModel:(NSString *)aModel mileage:(double)theMileage; // Comparison methods - (BOOL)isEqualToCar:(Car *)anotherCar; - (Car *)fasterCar:(Car *)anotherCar; - (Car *)slowerCar:(Car *)anotherCar;
  • 25. Upcoming Topics: Introduction to XCode Introduction to iPhone Architecture Essential COCOA Touch Classes Nib File and Story Board MVC Framework Intro to .H and .M Files THANK YOU