SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Learning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksLearning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksCalvin Cheng
 
Cocoa Design Patterns
Cocoa Design PatternsCocoa Design Patterns
Cocoa Design Patternssgleadow
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 
Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language Spring FrameWork Tutorials Java Language
Spring FrameWork Tutorials Java Language Mahika Tutorials
 
Localization and Accessibility on iOS
Localization and Accessibility on iOSLocalization and Accessibility on iOS
Localization and Accessibility on iOSMake School
 
Dependency Injection Inversion Of Control And Unity
Dependency Injection Inversion Of Control And UnityDependency Injection Inversion Of Control And Unity
Dependency Injection Inversion Of Control And Unityrainynovember12
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScriptLilia Sfaxi
 
Property wrapper and how to use them with mvvm in swift ui i copy
Property wrapper and how to use them with mvvm in swift ui i copyProperty wrapper and how to use them with mvvm in swift ui i copy
Property wrapper and how to use them with mvvm in swift ui i copyWannitaTolaema
 
iOS Memory management & Navigation
iOS Memory management & NavigationiOS Memory management & Navigation
iOS Memory management & NavigationMarian Ignev
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture Jiby John
 
Memory management in iOS.
Memory management in iOS.Memory management in iOS.
Memory management in iOS.HSIEH CHING-FAN
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEBenjamin Cabé
 
MVC and Entity Framework
MVC and Entity FrameworkMVC and Entity Framework
MVC and Entity FrameworkJames Johnson
 
Booa8 Slide 04
Booa8 Slide 04Booa8 Slide 04
Booa8 Slide 04oswchavez
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript DevelopmentAddy Osmani
 
Wade Not in Unknown Waters. Part Four.
Wade Not in Unknown Waters. Part Four.Wade Not in Unknown Waters. Part Four.
Wade Not in Unknown Waters. Part Four.PVS-Studio
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteRavi Bhadauria
 

Was ist angesagt? (20)

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

Ähnlich wie 02 objective-c session 2

Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...NicheTech Com. Solutions Pvt. Ltd.
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyUna Daly
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)Netcetera
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Java căn bản- Chapter1
Java  căn bản- Chapter1Java  căn bản- Chapter1
Java căn bản- Chapter1Vince Vo
 
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 DevelopmentEduardo Bergavera
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsSubhransu Behera
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatiasapientindia
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa TouchEliah Nikans
 
Ios development 2
Ios development 2Ios development 2
Ios development 2elnaqah
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesBlue Elephant Consulting
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Blue Elephant Consulting
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsRahul Malhotra
 

Ähnlich wie 02 objective-c session 2 (20)

Objective c
Objective cObjective c
Objective c
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
ios basics
ios basicsios basics
ios basics
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Java căn bản- Chapter1
Java  căn bản- Chapter1Java  căn bản- Chapter1
Java căn bản- Chapter1
 
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
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatia
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & Classes
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 

Mehr von Amr Elghadban (AmrAngry) (15)

Code detox
Code detoxCode detox
Code detox
 
08 objective-c session 8
08  objective-c session 808  objective-c session 8
08 objective-c session 8
 
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
 
05 objective-c session 5
05  objective-c session 505  objective-c session 5
05 objective-c session 5
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
03 objective-c session 3
03  objective-c session 303  objective-c session 3
03 objective-c session 3
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
00 intro ios
00 intro ios00 intro ios
00 intro ios
 
10- java language basics part4
10- java language basics part410- java language basics part4
10- java language basics part4
 
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
 
8- java language basics part2
8- java language basics part28- java language basics part2
8- java language basics part2
 
7-Java Language Basics Part1
7-Java Language Basics Part17-Java Language Basics Part1
7-Java Language Basics Part1
 
3-oop java-inheritance
3-oop java-inheritance3-oop java-inheritance
3-oop java-inheritance
 
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
 

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