際際滷

際際滷Share a Scribd company logo
Developing Mobile
Application
Ios : session # 2
By : Amr Elghadban
AMR
ELGHADBAN
ABOUT ME

SOFTWARE ENGINEER
FCI - HELWAN 2010
ITI INTAKE 32
WORKED BEFORE IN
- Tawasol IT
- Etisalat Masr
- NTG Clarity
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
What Is Objective C ?
Objective-C is the primary programming language you use when writing
software for OS X and iOS. Its a superset of the C programming language
and provides object-oriented capabilities and a dynamic runtime.
Objective-C inherits the syntax, primitive types, 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, what is object ???
every thing around us is consider as Object of Class
Object : Building, House, watch, Ahmed , etc
Class : architecture of buildings , etc
Class Object
Objects receive messages and objects are often referred as receivers.
by Calling it method behaviours Like Ahmed is an oBject receive an message to
eat, sleep, walk etc
Objects contain instance variables.
Ahmed Have , Eyes, Hands , legs , Head etc 
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
following concepts 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.
like Setter and getters
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.
you inherit from your father , and ur father super class / parent class
Mammals.
This existing class is called the base class, and the new class is referred to as
the derived class.
Objective-C allows only one level of inheritance, i.e., it can have only one
base class but allows multilevel inheritance for its own implementation. 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
Objective- C Basic Syntax
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 */
// hint can be write here
Objective- C Data Types
Data types refer to an extensive system used for declaring variables against 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
(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) Function types.
Objective- C Data Types
Primitive data type
int
float
double
char
bool
Class data type
NSObject
NSArray
NSString
Wrapping Class
Have a helper methods like converting from type to type
exp. NSInteger , NSNumber
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 Cs numeric
primitives. Its 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 onebut 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 doesnt.
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)
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 <- not use any more with
modern code
2."Automatic Reference Counting" or ARC
Objective- C Pointers
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;
Objective-C Methods
Methods represent the actions that an object knows how to perform.
Theyre the logical counterpart to properties, which represent an objects
data.
You can think of methods as functions that are attached to an object
however, they have a very different syntax.
-(void) methodName{
}
-(NSString *) methodToGenerate:(NSString *) stringValue{
NSString *newString =stringValue;
return newString;
}
ACCESS modifier
Methods can be access from class name or from the initiated object
Access modifier
+ : refer to class methods that can be access from class or object
- : refer to object method that can be only access from object
You can think of methods as functions that are attached to an object however, they
have a very different syntax.
+ (void) getClassName{
}
- (NSString *) methodToGenerate:(NSString *) stringValue{
NSString *newString =stringValue;
return newString;
}
Naming Convention
Naming Conventions:
Objective-C methods are designed to remove all ambiguities from an API.
Three simple rules for naming Objective-C methods:
1.Dont abbreviate anything.
2.Explicitly state parameter names in the method itself.
3.Explicitly describe the return value of the method.
- (int) returnIntValueForString: (NSString *) stringToBeOperated{
return [stringToBeOperated intValue];
}
// 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:
Essential COCOA Touch Classes
Nib File and Story Board
MVC Framework
Intro to .H and .M Files
THANKS
 Skype : amr_elghadban
 Email : amr.elghadban@gmail.com
 Phone : (+20) 1098558500
 Fb/amr.elghadban
 Linkedin/amr_elghadban
 ios_course facebook group : https://www.facebook.com/groups/
1161387897317786/
WISH YOU WONDERFUL DAY

More Related Content

What's hot (20)

Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
Eduardo Bergavera
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
Pranali Chaudhari
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
Ravi_Kant_Sahu
wrapper classes
wrapper classeswrapper classes
wrapper classes
Rajesh Roky
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software DevelopmentChapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Eduardo Bergavera
C++ classes
C++ classesC++ classes
C++ classes
imhammadali
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O MechanismsJava Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
Subhadra Sundar Chakraborty
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
JSpiders Basavanagudi
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
Garik Kalashyan
Java String
Java String Java String
Java String
SATYAM SHRIVASTAV
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
Eduardo Bergavera
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
Srinivas Narasegouda
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
wrapper classes
wrapper classeswrapper classes
wrapper classes
Rajesh Roky
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software DevelopmentChapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Eduardo Bergavera
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Sunny Shaikh
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
Garik Kalashyan

Similar to 01 objective-c session 1 (20)

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
Zafor Iqbal
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
HouseMusica
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
Mukund Trivedi
Objective c
Objective cObjective c
Objective c
ricky_chatur2005
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
JITTAYASHWANTHREDDY
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTSOOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
RajendraKumarRajouri1
C++ Programming with examples for B.Tech
C++ Programming with examples for B.TechC++ Programming with examples for B.Tech
C++ Programming with examples for B.Tech
ashutoshgupta1102
C#ppt
C#pptC#ppt
C#ppt
Sambasivarao Kurakula
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
Bca2030 object oriented programming c++
Bca2030   object oriented programming  c++Bca2030   object oriented programming  c++
Bca2030 object oriented programming c++
smumbahelp
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
Compare Infobase Limited
Intro to iOS Development Made by Many
Intro to iOS Development  Made by ManyIntro to iOS Development  Made by Many
Intro to iOS Development Made by Many
kenatmxm
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf
TheertheshTheertha1
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
Shanmuganathan C
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
Javier Gonzalez-Sanchez
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
ITNet
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
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
Zafor Iqbal
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
HouseMusica
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTSOOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
OOSD Lecture 1-1.pptx FOR ENGINEERING STUDENTS
RajendraKumarRajouri1
C++ Programming with examples for B.Tech
C++ Programming with examples for B.TechC++ Programming with examples for B.Tech
C++ Programming with examples for B.Tech
ashutoshgupta1102
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
Connex
Bca2030 object oriented programming c++
Bca2030   object oriented programming  c++Bca2030   object oriented programming  c++
Bca2030 object oriented programming c++
smumbahelp
C++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHatC++ Interview Questions and Answers PDF By ScholarHat
C++ Interview Questions and Answers PDF By ScholarHat
Scholarhat
Intro to iOS Development Made by Many
Intro to iOS Development  Made by ManyIntro to iOS Development  Made by Many
Intro to iOS Development Made by Many
kenatmxm
@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf@vtucode.in-module-1-c++-2022-scheme.pdf
@vtucode.in-module-1-c++-2022-scheme.pdf
TheertheshTheertha1
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
Shanmuganathan C
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
Javier Gonzalez-Sanchez
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
ITNet
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468

More from Amr Elghadban (AmrAngry) (15)

Code detox
Code detoxCode detox
Code detox
Amr Elghadban (AmrAngry)
08 objective-c session 8
08  objective-c session 808  objective-c session 8
08 objective-c session 8
Amr Elghadban (AmrAngry)
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
Amr Elghadban (AmrAngry)
05 objective-c session 5
05  objective-c session 505  objective-c session 5
05 objective-c session 5
Amr Elghadban (AmrAngry)
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
Amr Elghadban (AmrAngry)
03 objective-c session 3
03  objective-c session 303  objective-c session 3
03 objective-c session 3
Amr Elghadban (AmrAngry)
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
Amr Elghadban (AmrAngry)
00 intro ios
00 intro ios00 intro ios
00 intro ios
Amr Elghadban (AmrAngry)
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
Amr Elghadban (AmrAngry)
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
Amr Elghadban (AmrAngry)
8- java language basics part2
8- java language basics part28- java language basics part2
8- java language basics part2
Amr Elghadban (AmrAngry)
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
Amr Elghadban (AmrAngry)
3-oop java-inheritance
3-oop java-inheritance3-oop java-inheritance
3-oop java-inheritance
Amr Elghadban (AmrAngry)
1-oop java-object
1-oop java-object1-oop java-object
1-oop java-object
Amr Elghadban (AmrAngry)
0-oop java-intro
0-oop java-intro0-oop java-intro
0-oop java-intro
Amr Elghadban (AmrAngry)

01 objective-c session 1

  • 1. Developing Mobile Application Ios : session # 2 By : Amr Elghadban
  • 2. AMR ELGHADBAN ABOUT ME SOFTWARE ENGINEER FCI - HELWAN 2010 ITI INTAKE 32 WORKED BEFORE IN - Tawasol IT - Etisalat Masr - NTG Clarity
  • 3. 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
  • 4. What Is Objective C ? Objective-C is the primary programming language you use when writing software for OS X and iOS. Its a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. Objective-C inherits the syntax, primitive types, and adds syntax for defining classes and methods.
  • 5. Objective C Characteristics The class is defined in two different sections namely @interface and @implementation. Almost everything is in form of objects, what is object ??? every thing around us is consider as Object of Class Object : Building, House, watch, Ahmed , etc Class : architecture of buildings , etc Class Object
  • 6. Objects receive messages and objects are often referred as receivers. by Calling it method behaviours Like Ahmed is an oBject receive an message to eat, sleep, walk etc Objects contain instance variables. Ahmed Have , Eyes, Hands , legs , Head etc 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.
  • 7. Language Concepts: Fully supports object-oriented programming, including the following concepts of object-oriented development: Encapsulation , Data hiding Inheritance Polymorphism
  • 8. 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. like Setter and getters
  • 9. 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. you inherit from your father , and ur father super class / parent class Mammals. This existing class is called the base class, and the new class is referred to as the derived class. Objective-C allows only one level of inheritance, i.e., it can have only one base class but allows multilevel inheritance for its own implementation. All classes in Objective-C is derived from the superclass NSObject.
  • 10. Program Structure A Objective-C program basically consists of the following parts: Preprocessor Commands Interface Implementation Method Variables Statements & Expressions Comments
  • 11. Objective- C Basic Syntax 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 */ // hint can be write here
  • 12. Objective- C Data Types Data types refer to an extensive system used for declaring variables against 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 (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) Function types.
  • 13. Objective- C Data Types Primitive data type int float double char bool Class data type NSObject NSArray NSString Wrapping Class Have a helper methods like converting from type to type exp. NSInteger , NSNumber
  • 14. 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 Cs numeric primitives. Its 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]);
  • 15. 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, &, *, ?:)
  • 16. 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
  • 17. 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 onebut it returns a new string.
  • 18. 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.
  • 19. Mutable objects can be modified, immutable objects can't. Eg: NSMutableArray has addObject: removeObject: methods (and more), but NSArray doesnt. 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)
  • 20. 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 <- not use any more with modern code 2."Automatic Reference Counting" or ARC
  • 21. Objective- C Pointers 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;
  • 22. Objective-C Methods Methods represent the actions that an object knows how to perform. Theyre the logical counterpart to properties, which represent an objects data. You can think of methods as functions that are attached to an object however, they have a very different syntax. -(void) methodName{ } -(NSString *) methodToGenerate:(NSString *) stringValue{ NSString *newString =stringValue; return newString; }
  • 23. ACCESS modifier Methods can be access from class name or from the initiated object Access modifier + : refer to class methods that can be access from class or object - : refer to object method that can be only access from object You can think of methods as functions that are attached to an object however, they have a very different syntax. + (void) getClassName{ } - (NSString *) methodToGenerate:(NSString *) stringValue{ NSString *newString =stringValue; return newString; }
  • 24. Naming Convention Naming Conventions: Objective-C methods are designed to remove all ambiguities from an API. Three simple rules for naming Objective-C methods: 1.Dont abbreviate anything. 2.Explicitly state parameter names in the method itself. 3.Explicitly describe the return value of the method. - (int) returnIntValueForString: (NSString *) stringToBeOperated{ return [stringToBeOperated intValue]; }
  • 25. // 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;
  • 26. // 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;
  • 27. Upcoming Topics: Essential COCOA Touch Classes Nib File and Story Board MVC Framework Intro to .H and .M Files
  • 28. THANKS Skype : amr_elghadban Email : amr.elghadban@gmail.com Phone : (+20) 1098558500 Fb/amr.elghadban Linkedin/amr_elghadban ios_course facebook group : https://www.facebook.com/groups/ 1161387897317786/ WISH YOU WONDERFUL DAY