SlideShare 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 :
• Intro to .H and .M Files
• Making Class
• Creating Object
• Alloc & init vs new
• NSLOG
• MVC Framework
Class
Classes is the blueprint for Objects
Objective-C class definition
are separated into two files 

1- interface
2- implementation
Class
Define the class interface
@interface BankAccount : NSObject {
float accountBalance;
NSString * accountNumber;
}
-(float)withDraw:(float)amount;
-(void)deposit:(float)amount;
@end
Class
Define the class implementation
#import “BankAccount.h”
@implementation BankAccount
-(float)withDraw:(float)amount{
//calculate 

return amount;
}
-(void)deposit:(float)amount{
//record amount
}
@end
Method
Class methods (prefixed with + )
Instance methods (prefixed with -)
Creating Objects
From blueprint to reality
1- No concept of constructors in Objective_C
2- Regular methods create new instances
- Allocation and initialisation are performed separately
BankAccount * account =[[BankAccount alloc] init];
BankAccount *account2= [BankAccount new];
Creating Objects
NSObject define class method called alloc
Dynamic allocates memory for object
return a new instance of receiving class
BankAccount * account =[BankAccount alloc];
NSObject define instance method called init
implemented by subclasses to initialise instance after
memory for it has been allocated
subClasses can define several initializers
account = [account init];
alloc and init is almost always nested into single line
alloc and init
The alloc message allocates enough memory to hold all the instance variables for
an object, sets all the instance variables to zero values, and turns the memory into
an instance of the class; at no point during the initialization is the memory an
instance of the superclass.
The init message performs the set-up of the instance upon creation. The init method
is often written as follows:
- (id)init {
self = [super init];
if (self) {
// perform initialization of object here
}
return self;
}
init
- (id)init {
self = [super init];
if (self) {
// perform initialization of object here
}
return self;
}
In the above example, notice the id return type. This type stands for "pointer to any object" in Objective-C (See the
Dynamic typing section).
The initializer pattern is used to assure that the object is properly initialized by its superclass before the init method
performs its initialization. It performs the following actions:
self = [super init]
Sends the superclass instance an init message and assigns the result to self (pointer to the current object).
if (self)
Checks if the returned object pointer is valid before performing any initialization.
return self
Returns the value of self to the caller.
+new, they combine +alloc and -init
Instantiation with the default, no-parameter initializer:
MyObject *o = [[MyObject alloc] init];
Instantiation with a custom initializer:
MyObject *o = [[MyObject alloc] initWithString:myString];
In the case where no custom initialization is being performed,
the "new" method can often be used in place of the alloc-init
messages:
MyObject *o = [MyObject new];
custom initializer
Instantiation with the default, no-parameter initializer:
Student *studentOne = [[Student alloc] init];
Instantiation with a custom initializer:
Student * studentTwo=[…. alloc] initWithString:myString];
Lap # 1 :
1. create student class has two variables name and age
2. do custom init for name
NSLOG
NSLog may seem like a class, but it isn't.
NSLog is a Foundation lib function for printing debug statements to the
console. It is defined in NSObjCRuntime.h
void NSLog(NSString format, …);
NSLog isn't an Objective C function but a C function built into the foundation
of Cocoa. Therefore it conforms to basic C functions with variadic arguments.
Using
NSLog(@“ Hello”); //print —- > Hello
NSString * str = @“ world”;
NSLog(@“ %@”,str); //print —- > world
NSLog(@“Hello %@”,str); //print —- > Hello world
NSLOG
Lap # 2 :
1. create method in student to print name
2. create method in student to print age
3. create method in student to print age and name like the
following 

“ Hello X your age is Y ”
X —> name
Y —> age
Model-View-Controller
The Model-View-Controller (MVC) design pattern assigns objects in an application one of three
roles: model, view, or controller.
The pattern defines not only the roles objects play in the application, it defines the way objects
communicate with each other.
Each of the three types of objects is separated from the others by abstract boundaries and
communicates with objects of the other types across those boundaries.
The collection of objects of a certain MVC type in an application is sometimes referred to as a
layer—for example, model layer.=
MVC is central to a good design for a Cocoa application.
The benefits of adopting this pattern are numerous.
Many objects in these applications tend to be more reusable, and their interfaces tend to be
better defined.
Applications having an MVC design are also more easily extensible than other applications.
Moreover, many Cocoa technologies and architectures are based on MVC and require that your
custom objects play one of the MVC roles.
Model-View-Controller
Model-View-Controller
Model Objects
Model objects encapsulate the data specific to an application and define the logic
and computation that manipulate and process that data.
View Objects
A view object is an object in an application that users can see. A view object
knows how to draw itself and can respond to user actions. A major purpose of
view objects is to display data from the application’s model objects and to enable
the editing of that data. Despite this, view objects are typically decoupled from
model objects in an MVC application.
Controller Objects
A controller object acts as an intermediary between one or more of an
application’s view objects and one or more of its model objects. Controller objects
are thus a conduit through which view objects learn about changes in model
objects and vice versa.
Nib /XIb and Storyboard
a xib will typically represent one screenful of information
(though this is not a hard and fast rule), while the Storyboard
will represent many screens and often the entire application.
the storyboard is actually composed of multiple .xib files.
What’s the “best” car?
What’s your budget?
How many seats do you need?
Do you care about fuel consumption?
How do you feel about sports cars?
Nib /XIb and Storyboard
A classic beginner’s mistake is to create one massive project-wide
Storyboard. A Storyboard is a board with a story to tell. It shouldn't
be used to mix unrelated stories into one big volume.
Storyboards are best used with multiple interconnected view
controllers, as their major simplification is in transitioning between
view controllers.
Lap # 3:
1. create xib / nib
2. create story board with one view controller
iOS Architecture Is Layered
At the highest level, iOS acts as an intermediary between the
underlying hardware and the apps you create
iOS Architecture Is Layered
At the highest level, iOS acts as an intermediary between the
underlying hardware and the apps you create.
The iOS Technologies Are Packaged as Frameworks
Apple delivers most of its system interfaces in special packages
called frameworks. A framework is a directory that contains a
dynamic shared library and the resources (such as header files,
images, and helper apps) needed to support that library. To use
frameworks, you add them to your app project from Xcode.
iOS Architecture Is Layered
Cocoa Touch Layer
The Cocoa Touch layer contains key frameworks for
building iOS apps.
These frameworks define the appearance of your app.
They also provide the basic app infrastructure and
support for key technologies such as multitasking,
touch-based input, push notifications, and many high-
level system services.
iOS Architecture Is Layered
Media Layer
The Media layer contains the graphics, audio,
and video technologies you use to implement
multimedia experiences in your apps.
The technologies in this layer make it easy for
you to build apps that look and sound great.
ex: Core Graphics (also known as Quartz),
(AVFoundation.framework)
iOS Architecture Is Layered
Core Services Layer
The Core Services layer contains fundamental system services for
apps
ex :
1.Grand Central Dispatch (GCD)
2.The SQLite library lets you embed a lightweight SQL database
into your app
3.The Foundation framework provides the NSXMLParser class for
retrieving elements from an XML document
4.The Address Book framework (AddressBook.framework)
provides programmatic access to a user’s contacts database.
cocoa ui controlles
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

PDF
Introduction of Xcode
PDF
Everything about Object Oriented Programming
PDF
Intro to iOS Development • Made by Many
PDF
Introduction to iOS and Objective-C
PDF
Design Patterns in iOS
PPTX
OOP, API Design and MVP
PDF
Connect.Tech- Swift Memory Management
PPTX
iOS Beginners Lesson 2
Introduction of Xcode
Everything about Object Oriented Programming
Intro to iOS Development • Made by Many
Introduction to iOS and Objective-C
Design Patterns in iOS
OOP, API Design and MVP
Connect.Tech- Swift Memory Management
iOS Beginners Lesson 2

What's hot (20)

KEY
Learning iOS and hunting NSZombies in 3 weeks
KEY
Cocoa Design Patterns
PPTX
Solid OOPS
PPTX
Dependency injection - the right way
PPTX
Spring FrameWork Tutorials Java Language
PDF
Localization and Accessibility on iOS
PPTX
Dependency Injection Inversion Of Control And Unity
PDF
Client-side JavaScript
PDF
Property wrapper and how to use them with mvvm in swift ui i copy
PDF
iOS Memory management & Navigation
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
PDF
Iphone lecture imp
PDF
Memory management in iOS.
PPTX
Use Eclipse technologies to build a modern embedded IDE
PDF
Angular
PPTX
MVC and Entity Framework
PPT
Booa8 Slide 04
PDF
Large-Scale JavaScript Development
PDF
Wade Not in Unknown Waters. Part Four.
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Learning iOS and hunting NSZombies in 3 weeks
Cocoa Design Patterns
Solid OOPS
Dependency injection - the right way
Spring FrameWork Tutorials Java Language
Localization and Accessibility on iOS
Dependency Injection Inversion Of Control And Unity
Client-side JavaScript
Property wrapper and how to use them with mvvm in swift ui i copy
iOS Memory management & Navigation
jQquerysummit - Large-scale JavaScript Application Architecture
Iphone lecture imp
Memory management in iOS.
Use Eclipse technologies to build a modern embedded IDE
Angular
MVC and Entity Framework
Booa8 Slide 04
Large-Scale JavaScript Development
Wade Not in Unknown Waters. Part Four.
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Ad

Similar to 02 objective-c session 2 (20)

KEY
Objective-C Crash Course for Web Developers
PDF
FI MUNI 2012 - iOS Basics
PDF
MFF UK - Introduction to iOS
PPTX
Basic iOS Training with SWIFT - Part 1
PDF
Session 3 - Object oriented programming with Objective-C (part 1)
PPT
Ios development
PDF
Objective-C Is Not Java
PDF
iOS 101 - Xcode, Objective-C, iOS APIs
PPTX
iOS course day 1
PDF
Programming iOS 5 2nd Edition Matt Neuburg
PDF
Bootstrapping iPhone Development
PDF
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
PDF
Programming iOS 5 2nd Edition Matt Neuburg
KEY
Frederick web meetup slides
PDF
Louis Loizides iOS Programming Introduction
PDF
Никита Корчагин - Programming Apple iOS with Objective-C
PDF
iOS Programming Intro
PPTX
Code camp 2011 Getting Started with IOS, Una Daly
PPTX
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
PDF
iOS (7) Workshop
Objective-C Crash Course for Web Developers
FI MUNI 2012 - iOS Basics
MFF UK - Introduction to iOS
Basic iOS Training with SWIFT - Part 1
Session 3 - Object oriented programming with Objective-C (part 1)
Ios development
Objective-C Is Not Java
iOS 101 - Xcode, Objective-C, iOS APIs
iOS course day 1
Programming iOS 5 2nd Edition Matt Neuburg
Bootstrapping iPhone Development
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
Programming iOS 5 2nd Edition Matt Neuburg
Frederick web meetup slides
Louis Loizides iOS Programming Introduction
Никита Корчагин - Programming Apple iOS with Objective-C
iOS Programming Intro
Code camp 2011 Getting Started with IOS, Una Daly
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
iOS (7) Workshop
Ad

More from Amr Elghadban (AmrAngry) (15)

PPT
08 objective-c session 8
PDF
07 objective-c session 7
PDF
05 objective-c session 5
PPTX
04 objective-c session 4
PDF
03 objective-c session 3
PDF
01 objective-c session 1
PDF
PDF
10- java language basics part4
PDF
9-java language basics part3
PDF
8- java language basics part2
PDF
7-Java Language Basics Part1
PDF
3-oop java-inheritance
PDF
1-oop java-object
PDF
0-oop java-intro
08 objective-c session 8
07 objective-c session 7
05 objective-c session 5
04 objective-c session 4
03 objective-c session 3
01 objective-c session 1
10- java language basics part4
9-java language basics part3
8- java language basics part2
7-Java Language Basics Part1
3-oop java-inheritance
1-oop java-object
0-oop java-intro

02 objective-c session 2

  • 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 : • Intro to .H and .M Files • Making Class • Creating Object • Alloc & init vs new • NSLOG • MVC Framework
  • 4. Class Classes is the blueprint for Objects Objective-C class definition are separated into two files 
 1- interface 2- implementation
  • 5. Class Define the class interface @interface BankAccount : NSObject { float accountBalance; NSString * accountNumber; } -(float)withDraw:(float)amount; -(void)deposit:(float)amount; @end
  • 6. Class Define the class implementation #import “BankAccount.h” @implementation BankAccount -(float)withDraw:(float)amount{ //calculate 
 return amount; } -(void)deposit:(float)amount{ //record amount } @end
  • 7. Method Class methods (prefixed with + ) Instance methods (prefixed with -)
  • 8. Creating Objects From blueprint to reality 1- No concept of constructors in Objective_C 2- Regular methods create new instances - Allocation and initialisation are performed separately BankAccount * account =[[BankAccount alloc] init]; BankAccount *account2= [BankAccount new];
  • 9. Creating Objects NSObject define class method called alloc Dynamic allocates memory for object return a new instance of receiving class BankAccount * account =[BankAccount alloc]; NSObject define instance method called init implemented by subclasses to initialise instance after memory for it has been allocated subClasses can define several initializers account = [account init]; alloc and init is almost always nested into single line
  • 10. alloc and init The alloc message allocates enough memory to hold all the instance variables for an object, sets all the instance variables to zero values, and turns the memory into an instance of the class; at no point during the initialization is the memory an instance of the superclass. The init message performs the set-up of the instance upon creation. The init method is often written as follows: - (id)init { self = [super init]; if (self) { // perform initialization of object here } return self; }
  • 11. init - (id)init { self = [super init]; if (self) { // perform initialization of object here } return self; } In the above example, notice the id return type. This type stands for "pointer to any object" in Objective-C (See the Dynamic typing section). The initializer pattern is used to assure that the object is properly initialized by its superclass before the init method performs its initialization. It performs the following actions: self = [super init] Sends the superclass instance an init message and assigns the result to self (pointer to the current object). if (self) Checks if the returned object pointer is valid before performing any initialization. return self Returns the value of self to the caller.
  • 12. +new, they combine +alloc and -init Instantiation with the default, no-parameter initializer: MyObject *o = [[MyObject alloc] init]; Instantiation with a custom initializer: MyObject *o = [[MyObject alloc] initWithString:myString]; In the case where no custom initialization is being performed, the "new" method can often be used in place of the alloc-init messages: MyObject *o = [MyObject new];
  • 13. custom initializer Instantiation with the default, no-parameter initializer: Student *studentOne = [[Student alloc] init]; Instantiation with a custom initializer: Student * studentTwo=[…. alloc] initWithString:myString]; Lap # 1 : 1. create student class has two variables name and age 2. do custom init for name
  • 14. NSLOG NSLog may seem like a class, but it isn't. NSLog is a Foundation lib function for printing debug statements to the console. It is defined in NSObjCRuntime.h void NSLog(NSString format, …); NSLog isn't an Objective C function but a C function built into the foundation of Cocoa. Therefore it conforms to basic C functions with variadic arguments. Using NSLog(@“ Hello”); //print —- > Hello NSString * str = @“ world”; NSLog(@“ %@”,str); //print —- > world NSLog(@“Hello %@”,str); //print —- > Hello world
  • 15. NSLOG Lap # 2 : 1. create method in student to print name 2. create method in student to print age 3. create method in student to print age and name like the following 
 “ Hello X your age is Y ” X —> name Y —> age
  • 16. Model-View-Controller The Model-View-Controller (MVC) design pattern assigns objects in an application one of three roles: model, view, or controller. The pattern defines not only the roles objects play in the application, it defines the way objects communicate with each other. Each of the three types of objects is separated from the others by abstract boundaries and communicates with objects of the other types across those boundaries. The collection of objects of a certain MVC type in an application is sometimes referred to as a layer—for example, model layer.= MVC is central to a good design for a Cocoa application. The benefits of adopting this pattern are numerous. Many objects in these applications tend to be more reusable, and their interfaces tend to be better defined. Applications having an MVC design are also more easily extensible than other applications. Moreover, many Cocoa technologies and architectures are based on MVC and require that your custom objects play one of the MVC roles.
  • 18. Model-View-Controller Model Objects Model objects encapsulate the data specific to an application and define the logic and computation that manipulate and process that data. View Objects A view object is an object in an application that users can see. A view object knows how to draw itself and can respond to user actions. A major purpose of view objects is to display data from the application’s model objects and to enable the editing of that data. Despite this, view objects are typically decoupled from model objects in an MVC application. Controller Objects A controller object acts as an intermediary between one or more of an application’s view objects and one or more of its model objects. Controller objects are thus a conduit through which view objects learn about changes in model objects and vice versa.
  • 19. Nib /XIb and Storyboard a xib will typically represent one screenful of information (though this is not a hard and fast rule), while the Storyboard will represent many screens and often the entire application. the storyboard is actually composed of multiple .xib files. What’s the “best” car? What’s your budget? How many seats do you need? Do you care about fuel consumption? How do you feel about sports cars?
  • 20. Nib /XIb and Storyboard A classic beginner’s mistake is to create one massive project-wide Storyboard. A Storyboard is a board with a story to tell. It shouldn't be used to mix unrelated stories into one big volume. Storyboards are best used with multiple interconnected view controllers, as their major simplification is in transitioning between view controllers. Lap # 3: 1. create xib / nib 2. create story board with one view controller
  • 21. iOS Architecture Is Layered At the highest level, iOS acts as an intermediary between the underlying hardware and the apps you create
  • 22. iOS Architecture Is Layered At the highest level, iOS acts as an intermediary between the underlying hardware and the apps you create. The iOS Technologies Are Packaged as Frameworks Apple delivers most of its system interfaces in special packages called frameworks. A framework is a directory that contains a dynamic shared library and the resources (such as header files, images, and helper apps) needed to support that library. To use frameworks, you add them to your app project from Xcode.
  • 23. iOS Architecture Is Layered Cocoa Touch Layer The Cocoa Touch layer contains key frameworks for building iOS apps. These frameworks define the appearance of your app. They also provide the basic app infrastructure and support for key technologies such as multitasking, touch-based input, push notifications, and many high- level system services.
  • 24. iOS Architecture Is Layered Media Layer The Media layer contains the graphics, audio, and video technologies you use to implement multimedia experiences in your apps. The technologies in this layer make it easy for you to build apps that look and sound great. ex: Core Graphics (also known as Quartz), (AVFoundation.framework)
  • 25. iOS Architecture Is Layered Core Services Layer The Core Services layer contains fundamental system services for apps ex : 1.Grand Central Dispatch (GCD) 2.The SQLite library lets you embed a lightweight SQL database into your app 3.The Foundation framework provides the NSXMLParser class for retrieving elements from an XML document 4.The Address Book framework (AddressBook.framework) provides programmatic access to a user’s contacts database.
  • 27. 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