SlideShare une entreprise Scribd logo
1  sur  40
iOS Training
(Basics)
Gurpreet Singh
Sriram Viswanathan

Yahoo! Confidential

1
Topics
 Getting Started
 Introduction to Xcode and Application settings
 Understanding App execution flow

 Introduction to Objective-C
 Writing your First iPhone Application
 Introduction to Interface Builder
 Outlets and Actions
 Storyboards
 Using the iPhone/iPad Simulator

Yahoo! Confidential

2
Some Interesting Facts
 What does ‘i’ stands for in iPhone?
 iPhone 5 was world’s best selling smartphone in Q4 2012, iPhone
5 and iPhone 4S put together accounted for 1 in every 5
smartphones shipped in Q4.
 Total iPhones sold till date – 250 million
 Total iPads sold till date – 100 million

 People spend $1 million / day in Apple App store.
 App store has 8 lacs active apps as of March 2013
 40 billion app downloads as of March 2013

Yahoo! Confidential

3
Topics
 Getting Started
 Introduction to Xcode and Application settings
 Understanding App execution flow

 Introduction to Objective-C
 Writing your First iPhone Application
 Introduction to Interface Builder
 Outlets and Actions
 Storyboards
 Using the iPhone/iPad Simulator

Yahoo! Confidential

4
Introduction to Xcode

Xcode

Yahoo! Confidential

5
Topics
 Getting Started
 Introduction to Xcode and Application settings
 Understanding App execution flow

 Introduction to Objective-C
 Writing your First iPhone Application
 Introduction to Interface Builder
 Outlets and Actions
 Storyboards
 Using the iPhone/iPad Simulator

Yahoo! Confidential

6
Understanding App Execution Flow

App execution flow

Yahoo! Confidential

7
Understanding App Execution Flow

Not running
Foreground

Inactive

Active

Background
Suspended
Yahoo! Confidential

8
App Delegate Methods
 application:willFinishLaunchingWithOptions
 application:didFinishLaunchingWithOptions
 applicationDidBecomeActive

 applicationWillResignAcitve
 applicationDidEnterBackground

 applicationWillEnterForeground
 applicationWillTerminate
Yahoo! Confidential

9
App Launch Cycle
User taps icon
main()
UIApplicationMain()
Load main UI File
First Initialization

application:willFinishLaunchingWithOptions

Restore UI state

Various methods

Final Initialization

application:didFinishLaunchingWithOptions

Activate the App

application:didBecomeActive

Event Loop
Yahoo! Confidential

Handle Events
10
Topics
 Getting Started
 Introduction to Xcode and Application settings
 Understanding App execution flow

 Introduction to Objective-C
 Writing your First iPhone Application
 Introduction to Interface Builder
 Outlets and Actions
 Storyboards
 Using the iPhone/iPad Simulator

Yahoo! Confidential

11
Objective C Basics
 Objective C is layered on top of C language
 Is a superset of C

 Provides object-oriented capabilities

 NeXT Software licensed Objective C in 1988
 Apple acquired NeXT in 1996
 Today it is the native language for developing applications for Mac OS X
and iOS

 All of the syntax for non-object-oriented operations (including primitive
variables, expressions, function declarations) are identical to that of C
 While the syntax for object-oriented features is an implementation of
messaging.
 You might find its syntax a bit complex in starting but will get used to as
you progress.

Yahoo! Confidential

12
Objective C Basics
Creating objects
In other languages, you create objects like this:
object = new Class();

The same in Objective C will look like
object = [[Class alloc] init];

There might be some cases when you may want to pass some input while
creating objects.
In other languages you pass the input to the constructor like this:
object = new Class(2);

The same in Objective C you will do the same like this
object = [[Class alloc] initWithInt:2];

Yahoo! Confidential

13
Objective C Basics
Some points to note about objects in Objective C
 All object variable are pointers
 Object must be alloc'ed and init'ed
 When you declare a variable to store an object you need to mention type of object it
will hold.
Class *object;
object = [[Class alloc] init];
 Keyword id is just a way of saying any object
id object;
object = [[Class alloc] init];
 id doesn't use pointer notation
 Keyword nil just means no object
Class *object = nil;

Yahoo! Confidential

14
Objective C Basics
Declaring methods
A simple method declaration in other languages will look like
setX(n)
or
setX (int n);
or

void setX (int n);

The same in Objective C will look like
- (void) setX: (int) n;

Yahoo! Confidential

15
Objective C Basics
Method declaration explained

- (void) setX: (int)
n;

Method type:
+ = class method
- = instance method

Yahoo! Confidential

Return type

Method name

Argument type

Argument name

16
Objective C Basics
Calling methods
A simple method call in other languages will look like
output = object.method();
output = object.method(inputParameter);

The same in Objective C will look like
output = [object method];
output = [object method:inputParameter];

Yahoo! Confidential

17
Objective C Basics
Nested method calls
In many languages, nested method or method calls look like this:
object.function1 ( object.function2() );

The same in Objective C will look like
[object function1:[object function2]];
e.g. [[Class alloc] init]
Multi-input methods
A simple multi-input method call in other languages will look like
object.setXAndY(3, 2);

The same in Objective C will look like
[object setX:3 andY:2];

Yahoo! Confidential

18
Objective C Basics
Multi-input methods explained

[object setX:3 andY:2]
Beginning Method
Call Syntax

Object of the Class
containing the method

First parameter
value

First named
parameter

Yahoo! Confidential

Ending Method
Call Syntax
Second parameter
value

Second named
parameter

19
Objective C Basics
Creating classes
 The specification of a class in Objective-C requires two distinct pieces: the
interface and the implementation.
 The interface portion contains the class declaration and defines the instance
variables and methods associated with the class.
 The interface is usually in a .h file.

 The implementation portion contains the actual code for the methods of the class.
 The implementation is usually in a .m file.
 When you want to include header files in your source code, you typically use a
#import directive.
 This is like #include, except that it makes sure that the same file is never
included more than once.

Yahoo! Confidential

20
Objective C Basics
Example:

@interface Movie: NSObject {
NSString *name;
}
- (id) initWithString: (NSString *) movieName;
+ (Movie *) createMovieWithName: (NSString *) movieName;
@end

Yahoo! Confidential

21
Objective C Basics
#import Movie.h;
@implementation Movie
- (id) initWithString: (NSString *) movieName {
self = [super init];
if (self) {
name = movieName;
}
return self;
}
+ (Movie *) createMovieWithName: (NSString *) movieName {
return [[self alloc] initWithString: movieName];
}
@end

Yahoo! Confidential

Same as this (keyword) in other languages

22
Objective C Basics
Some points to note about #import
 Movie.m file includes Movie.h file.

 Wherever we want to use Movie object we import Movie.h file (we never import
Movie.m file)
 Use @class to avoid circular reference (class A needs to import class B and class
B needs to import class A).
@class B;
@interface A: NSObject
- (B*) calculateMyBNess;
@end
@class A;
@interface B: NSObject
- (A*) calculateMyANess;
@end
 This concept is called forward declaration, tells compiler trust me there is class
called class B
Yahoo! Confidential

23
Objective C Basics
There are some issues in previous example (Movie Class)
 By default all methods are public in objective C

 By default all instance variables are private in objective C
 What if I directly call initWithString instead of createMovieWithName?
 We need to make initWithString private.
 Secondly, what if I don’t know the movie name upfront and I want to create the
Movie object and then assign the name of movie later?
 We have to provide public methods (getter and setter) to get and set the
movie name.

Yahoo! Confidential

24
Objective C Basics
Using Private Methods

@interface Movie: NSObject {
NSString *name;
}
- (id) initWithString: (NSString *) movieName;
+ (Movie *) createMovieWithName: (NSString *) movieName;
@end

Yahoo! Confidential

25
Objective C Basics
#import Movie.h;
@interface Movie (private)
- (id) initWithString: (NSString *) movieName;
@end
@implementation Movie
- (id) initWithString: (NSString *) movieName {
self = [super init];
if (self) {
name = movieName;
}
return self;
}
+ (Movie *) createMovieWithName: (NSString *) movieName {
return [[self alloc] initWithString: movieName];
}
@end
Yahoo! Confidential

26
Objective C Basics
Adding getter and setter methods
 Note, in objective C, as per convention the getter method for a variable named ‘age’
is not ‘getAge’, in fact it is called as ‘age’ only.
 But, the setter method for variable ‘age’ will be called as ‘setAge’.
 So in our example, getter method will be movie.name and setter method will be
movie.setName

Yahoo! Confidential

27
Objective C Basics
Adding getter and setter methods

@interface Movie: NSObject {
NSString *name;
}
- (NSString *) name;
- (void) setName: (NSString *) movieName;
+ (Movie *) createMovieWithName: (NSString *) movieName;
@end

Yahoo! Confidential

28
Objective C Basics
…
@implementation Movie
- (NSString *) name {
return name;
}
- (void) setName: (NSString *) movieName {
if (![name isEqualToString: movieName]) {
name = movieName;
}
}
…
@end
Usage
Movie *myMovie = [[Movie alloc] init];
[myMovie setName:@”Dhoom”];
NSString *movieName = [myMovie name];
Yahoo! Confidential

29
Objective C Basics
Using @property and @synthesize directive
 Adding getter / setter methods for all the instance variables can become a tedious
task.
 Apple provide a simple way for this, you can use @property directive
 Benefits
 You do not have to write getter and setter methods yourself.
 You can define the "assigning behavior" (namely copy, strong, weak,
nonatomic)
Keywords:
•

copy: The object is copied to the ivar when set

•

strong: The object is retained on set

•

weak: The object's pointer is assigned to the ivar when set and will be set to nil
automatically when the instance is deallocated

•

nonatomic: The accessor is not @synchronized (threadsafe), and therefore faster

•

atomic: The accessor is @synchronized (threadsafe), and therefore slower

Yahoo! Confidential

30
Objective C Basics
Using @property and @synthesize directive
@interface Movie: NSObject {
NSString *name;
}
@property (nonatomic, strong) NSString *name;

- (NSString *) name;
- (void) setName: (NSString *) movieName;
+ (Movie *) createMovieWithName: (NSString *) movieName;
@end

Yahoo! Confidential

31
Objective C Basics
…
@implementation Movie
@synthesize name;
- (NSString *) name {
return name;
}
- (void) setName: (NSString *) movieName {
if (![name isEqualToString: movieName]) {
name = movieName;
}
}
…
@end

Yahoo! Confidential

32
Objective C Basics
To sum up:
NSString *name; - declares an instance variable 'name'
@property (nonatomic, strong) NSString *name; - declares the accessor methods for 'name'
@synthesize name; - implements the accessor methods for 'name'

Yahoo! Confidential

33
Objective C Basics
Using strings (NSString class)
NSString *movieName = @”Dhoom”;
The @ symbol
Ok, why does this funny @ sign show up all the time? Well, Objective-C is an extension of
the C-language, which has its own ways to deal with strings. To differentiate the new type of
strings, which are fully-fledged objects, Objective-C uses an @ sign.

A new kind of string
How does Objective-C improve on strings of the C language? Well, Objective-C strings are
Unicode strings instead of ASCII strings. Unicode-strings can display characters of just about
any language, such as Chinese, as well as the Roman alphabet.
A C string is simply a series of characters (a one-dimensional character array) that is nullterminated, whereas an NSString object is a complete object with class methods, instance
methods, etc.
Note: It is possible (but not recommended) to use C language strings in Objective C.

Yahoo! Confidential

34
Objective C Basics
Using ‘stringWithFormat’
NSString *movieName = [NSString stringWithFormat:@”Dhoom %d”, 2]; // Dhoom 2

Specifiers:
%d
%f
%@

Signed 32-bit integer (int)
64-bit floating-point number (double)
Objective-C object

Complete list of format specifiers is available here.
Introduction to NSLog
NSLog(@”Movie name is %@”, movieName);





Format specifiers same as ‘stringWithFormat’.
Used for debugging
Same as error_log in PHP or console.log in JavaScript
Note the use of round brackets unlike other method calls in objective C

Yahoo! Confidential

35
Objective C Basics
Using arrays (NSArray class)
 Provide random access
 The objects contained in an array do not all have to be of the same type.
Factory methods (static methods that build array from given parameters):
+ (id)array
Creates and returns an empty array
+ (id)arrayWithObjects
Creates and returns an array containing a given object
Lot of such factory methods available
Accessing the NSArray
- (BOOL)containsObject:(id)anObject
- (NSUInteger)count
- (id)lastObject
- (id)objectAtIndex:(NSUInteger)index

Yahoo! Confidential

Returns true if a given object is found in the array
Returns the size of the array
Returns the last object in the array
Returns the object at a given index.

36
Objective C Basics
Introduction to NSMutableArray
 NSArray is immutable (content of array cannot be modified without recreating it)
 You can create mutable arrays (NSMutableArray) if you want to add or remove elements
after creating.
Additional functions to manipulate the array
insertObject:atIndex:
removeObjectAtIndex:
addObject:
removeLastObject
replaceObjectAtIndex:withObject:

Yahoo! Confidential

37
Objective C Basics
Introduction to NSDictionary
 NSDictionary are like Maps and Hashes in other languages
 Key-value pairs
 It is an unordered collection of objects
Factory methods (static methods that build array from given parameters):
+ (id)dictionary
Creates and returns an empty dictionary
+ (id)dictionaryWithObjects: forKeys:
Creates and returns a dictionary containing entries
constructed from the contents of an array of keys
and an array of values
Lot of such factory methods available
Accessing the NSDictionary
– allKeys
– allValues
– objectForKey:

Yahoo! Confidential

Returns a new array containing the dictionary’s keys.
Returns a new array containing the dictionary’s values.
Returns the value associated with a given key.

38
Objective C Basics
Introduction to NSMutableDictionary
 Similar to NSArray, NSDictionary is also immutable
 You can create mutable dictionary (NSMutableDictionary) if you want to add or remove
objects after creating.
Additional functions to manipulate the dictionary
setObject:forKey:
removeObjectForKey:
removeAllObjects:
removeObjectsForKeys:
Points to note:
 NSArray and NSDictionary only store objects
 So if you want to store numbers then you have to convert it to NSNumber
 Use NSNull for empty values

Yahoo! Confidential

39
Topics
 Getting Started
 Introduction to Xcode and Application settings
 Understanding App execution flow

 Introduction to Objective-C
 Writing your First iPhone Application
 Introduction to Interface Builder
 Outlets and Actions
 Storyboards
 Using the iPhone/iPad Simulator

Yahoo! Confidential

40

Contenu connexe

Tendances

An Objective-C Primer
An Objective-C PrimerAn Objective-C Primer
An Objective-C Primer
Babul Mirdha
 
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTCode Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
dschaefer
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
FALLEE31188
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
Hadziq Fabroyir
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
Ray Ploski
 

Tendances (20)

Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
.NET Coding Standards For The Real World (2012)
.NET Coding Standards For The Real World (2012).NET Coding Standards For The Real World (2012)
.NET Coding Standards For The Real World (2012)
 
An Objective-C Primer
An Objective-C PrimerAn Objective-C Primer
An Objective-C Primer
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 
Eclipse Con 2015: Codan - a C/C++ Code Analysis Framework for CDT
Eclipse Con 2015: Codan - a C/C++ Code Analysis Framework for CDTEclipse Con 2015: Codan - a C/C++ Code Analysis Framework for CDT
Eclipse Con 2015: Codan - a C/C++ Code Analysis Framework for CDT
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API REST
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
PhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginPhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 Plugin
 
Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTCode Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
 
Managed Compiler
Managed CompilerManaged Compiler
Managed Compiler
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure#OOP_D_ITS - 4th - C++ Oop And Class Structure
#OOP_D_ITS - 4th - C++ Oop And Class Structure
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Python introduction
Python introductionPython introduction
Python introduction
 
How to Profit from Static Analysis
How to Profit from Static AnalysisHow to Profit from Static Analysis
How to Profit from Static Analysis
 

En vedette (8)

2011 iOS & Android 市場數據報告
2011 iOS & Android 市場數據報告2011 iOS & Android 市場數據報告
2011 iOS & Android 市場數據報告
 
iPhone application development training day 1
iPhone application development training day 1iPhone application development training day 1
iPhone application development training day 1
 
Training Session iOS UI Guidelines
Training Session iOS UI GuidelinesTraining Session iOS UI Guidelines
Training Session iOS UI Guidelines
 
Introduction to iOS Apps Development
Introduction to iOS Apps DevelopmentIntroduction to iOS Apps Development
Introduction to iOS Apps Development
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS Introduction
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
iOS PPT
iOS PPTiOS PPT
iOS PPT
 

Similaire à iOS training (basic)

I Phone Development Presentation
I Phone Development PresentationI Phone Development Presentation
I Phone Development Presentation
Aessam
 

Similaire à iOS training (basic) (20)

Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
iOS Programming - MCV (Delegate/Protocols/Property&Syntax)
 
Ios - Introduction to platform & SDK
Ios - Introduction to platform & SDKIos - Introduction to platform & SDK
Ios - Introduction to platform & SDK
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guide
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Presentation1 password
Presentation1 passwordPresentation1 password
Presentation1 password
 
I Phone Development Presentation
I Phone Development PresentationI Phone Development Presentation
I Phone Development Presentation
 
Objective c
Objective cObjective c
Objective c
 
Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I) Formacion en movilidad: Conceptos de desarrollo en iOS (I)
Formacion en movilidad: Conceptos de desarrollo en iOS (I)
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdf
 
A quick and dirty intro to objective c
A quick and dirty intro to objective cA quick and dirty intro to objective c
A quick and dirty intro to objective c
 
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesC# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
Pioc
PiocPioc
Pioc
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
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
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 

Plus de Gurpreet Singh Sachdeva (6)

iOS App performance - Things to take care
iOS App performance - Things to take careiOS App performance - Things to take care
iOS App performance - Things to take care
 
Firefox addons
Firefox addonsFirefox addons
Firefox addons
 
Introduction to Greasemonkey
Introduction to GreasemonkeyIntroduction to Greasemonkey
Introduction to Greasemonkey
 
iOS training (advanced)
iOS training (advanced)iOS training (advanced)
iOS training (advanced)
 
iOS training (intermediate)
iOS training (intermediate)iOS training (intermediate)
iOS training (intermediate)
 
Introduction to Data Warehousing
Introduction to Data WarehousingIntroduction to Data Warehousing
Introduction to Data Warehousing
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

iOS training (basic)

  • 1. iOS Training (Basics) Gurpreet Singh Sriram Viswanathan Yahoo! Confidential 1
  • 2. Topics  Getting Started  Introduction to Xcode and Application settings  Understanding App execution flow  Introduction to Objective-C  Writing your First iPhone Application  Introduction to Interface Builder  Outlets and Actions  Storyboards  Using the iPhone/iPad Simulator Yahoo! Confidential 2
  • 3. Some Interesting Facts  What does ‘i’ stands for in iPhone?  iPhone 5 was world’s best selling smartphone in Q4 2012, iPhone 5 and iPhone 4S put together accounted for 1 in every 5 smartphones shipped in Q4.  Total iPhones sold till date – 250 million  Total iPads sold till date – 100 million  People spend $1 million / day in Apple App store.  App store has 8 lacs active apps as of March 2013  40 billion app downloads as of March 2013 Yahoo! Confidential 3
  • 4. Topics  Getting Started  Introduction to Xcode and Application settings  Understanding App execution flow  Introduction to Objective-C  Writing your First iPhone Application  Introduction to Interface Builder  Outlets and Actions  Storyboards  Using the iPhone/iPad Simulator Yahoo! Confidential 4
  • 6. Topics  Getting Started  Introduction to Xcode and Application settings  Understanding App execution flow  Introduction to Objective-C  Writing your First iPhone Application  Introduction to Interface Builder  Outlets and Actions  Storyboards  Using the iPhone/iPad Simulator Yahoo! Confidential 6
  • 7. Understanding App Execution Flow App execution flow Yahoo! Confidential 7
  • 8. Understanding App Execution Flow Not running Foreground Inactive Active Background Suspended Yahoo! Confidential 8
  • 9. App Delegate Methods  application:willFinishLaunchingWithOptions  application:didFinishLaunchingWithOptions  applicationDidBecomeActive  applicationWillResignAcitve  applicationDidEnterBackground  applicationWillEnterForeground  applicationWillTerminate Yahoo! Confidential 9
  • 10. App Launch Cycle User taps icon main() UIApplicationMain() Load main UI File First Initialization application:willFinishLaunchingWithOptions Restore UI state Various methods Final Initialization application:didFinishLaunchingWithOptions Activate the App application:didBecomeActive Event Loop Yahoo! Confidential Handle Events 10
  • 11. Topics  Getting Started  Introduction to Xcode and Application settings  Understanding App execution flow  Introduction to Objective-C  Writing your First iPhone Application  Introduction to Interface Builder  Outlets and Actions  Storyboards  Using the iPhone/iPad Simulator Yahoo! Confidential 11
  • 12. Objective C Basics  Objective C is layered on top of C language  Is a superset of C  Provides object-oriented capabilities  NeXT Software licensed Objective C in 1988  Apple acquired NeXT in 1996  Today it is the native language for developing applications for Mac OS X and iOS  All of the syntax for non-object-oriented operations (including primitive variables, expressions, function declarations) are identical to that of C  While the syntax for object-oriented features is an implementation of messaging.  You might find its syntax a bit complex in starting but will get used to as you progress. Yahoo! Confidential 12
  • 13. Objective C Basics Creating objects In other languages, you create objects like this: object = new Class(); The same in Objective C will look like object = [[Class alloc] init]; There might be some cases when you may want to pass some input while creating objects. In other languages you pass the input to the constructor like this: object = new Class(2); The same in Objective C you will do the same like this object = [[Class alloc] initWithInt:2]; Yahoo! Confidential 13
  • 14. Objective C Basics Some points to note about objects in Objective C  All object variable are pointers  Object must be alloc'ed and init'ed  When you declare a variable to store an object you need to mention type of object it will hold. Class *object; object = [[Class alloc] init];  Keyword id is just a way of saying any object id object; object = [[Class alloc] init];  id doesn't use pointer notation  Keyword nil just means no object Class *object = nil; Yahoo! Confidential 14
  • 15. Objective C Basics Declaring methods A simple method declaration in other languages will look like setX(n) or setX (int n); or void setX (int n); The same in Objective C will look like - (void) setX: (int) n; Yahoo! Confidential 15
  • 16. Objective C Basics Method declaration explained - (void) setX: (int) n; Method type: + = class method - = instance method Yahoo! Confidential Return type Method name Argument type Argument name 16
  • 17. Objective C Basics Calling methods A simple method call in other languages will look like output = object.method(); output = object.method(inputParameter); The same in Objective C will look like output = [object method]; output = [object method:inputParameter]; Yahoo! Confidential 17
  • 18. Objective C Basics Nested method calls In many languages, nested method or method calls look like this: object.function1 ( object.function2() ); The same in Objective C will look like [object function1:[object function2]]; e.g. [[Class alloc] init] Multi-input methods A simple multi-input method call in other languages will look like object.setXAndY(3, 2); The same in Objective C will look like [object setX:3 andY:2]; Yahoo! Confidential 18
  • 19. Objective C Basics Multi-input methods explained [object setX:3 andY:2] Beginning Method Call Syntax Object of the Class containing the method First parameter value First named parameter Yahoo! Confidential Ending Method Call Syntax Second parameter value Second named parameter 19
  • 20. Objective C Basics Creating classes  The specification of a class in Objective-C requires two distinct pieces: the interface and the implementation.  The interface portion contains the class declaration and defines the instance variables and methods associated with the class.  The interface is usually in a .h file.  The implementation portion contains the actual code for the methods of the class.  The implementation is usually in a .m file.  When you want to include header files in your source code, you typically use a #import directive.  This is like #include, except that it makes sure that the same file is never included more than once. Yahoo! Confidential 20
  • 21. Objective C Basics Example: @interface Movie: NSObject { NSString *name; } - (id) initWithString: (NSString *) movieName; + (Movie *) createMovieWithName: (NSString *) movieName; @end Yahoo! Confidential 21
  • 22. Objective C Basics #import Movie.h; @implementation Movie - (id) initWithString: (NSString *) movieName { self = [super init]; if (self) { name = movieName; } return self; } + (Movie *) createMovieWithName: (NSString *) movieName { return [[self alloc] initWithString: movieName]; } @end Yahoo! Confidential Same as this (keyword) in other languages 22
  • 23. Objective C Basics Some points to note about #import  Movie.m file includes Movie.h file.  Wherever we want to use Movie object we import Movie.h file (we never import Movie.m file)  Use @class to avoid circular reference (class A needs to import class B and class B needs to import class A). @class B; @interface A: NSObject - (B*) calculateMyBNess; @end @class A; @interface B: NSObject - (A*) calculateMyANess; @end  This concept is called forward declaration, tells compiler trust me there is class called class B Yahoo! Confidential 23
  • 24. Objective C Basics There are some issues in previous example (Movie Class)  By default all methods are public in objective C  By default all instance variables are private in objective C  What if I directly call initWithString instead of createMovieWithName?  We need to make initWithString private.  Secondly, what if I don’t know the movie name upfront and I want to create the Movie object and then assign the name of movie later?  We have to provide public methods (getter and setter) to get and set the movie name. Yahoo! Confidential 24
  • 25. Objective C Basics Using Private Methods @interface Movie: NSObject { NSString *name; } - (id) initWithString: (NSString *) movieName; + (Movie *) createMovieWithName: (NSString *) movieName; @end Yahoo! Confidential 25
  • 26. Objective C Basics #import Movie.h; @interface Movie (private) - (id) initWithString: (NSString *) movieName; @end @implementation Movie - (id) initWithString: (NSString *) movieName { self = [super init]; if (self) { name = movieName; } return self; } + (Movie *) createMovieWithName: (NSString *) movieName { return [[self alloc] initWithString: movieName]; } @end Yahoo! Confidential 26
  • 27. Objective C Basics Adding getter and setter methods  Note, in objective C, as per convention the getter method for a variable named ‘age’ is not ‘getAge’, in fact it is called as ‘age’ only.  But, the setter method for variable ‘age’ will be called as ‘setAge’.  So in our example, getter method will be movie.name and setter method will be movie.setName Yahoo! Confidential 27
  • 28. Objective C Basics Adding getter and setter methods @interface Movie: NSObject { NSString *name; } - (NSString *) name; - (void) setName: (NSString *) movieName; + (Movie *) createMovieWithName: (NSString *) movieName; @end Yahoo! Confidential 28
  • 29. Objective C Basics … @implementation Movie - (NSString *) name { return name; } - (void) setName: (NSString *) movieName { if (![name isEqualToString: movieName]) { name = movieName; } } … @end Usage Movie *myMovie = [[Movie alloc] init]; [myMovie setName:@”Dhoom”]; NSString *movieName = [myMovie name]; Yahoo! Confidential 29
  • 30. Objective C Basics Using @property and @synthesize directive  Adding getter / setter methods for all the instance variables can become a tedious task.  Apple provide a simple way for this, you can use @property directive  Benefits  You do not have to write getter and setter methods yourself.  You can define the "assigning behavior" (namely copy, strong, weak, nonatomic) Keywords: • copy: The object is copied to the ivar when set • strong: The object is retained on set • weak: The object's pointer is assigned to the ivar when set and will be set to nil automatically when the instance is deallocated • nonatomic: The accessor is not @synchronized (threadsafe), and therefore faster • atomic: The accessor is @synchronized (threadsafe), and therefore slower Yahoo! Confidential 30
  • 31. Objective C Basics Using @property and @synthesize directive @interface Movie: NSObject { NSString *name; } @property (nonatomic, strong) NSString *name; - (NSString *) name; - (void) setName: (NSString *) movieName; + (Movie *) createMovieWithName: (NSString *) movieName; @end Yahoo! Confidential 31
  • 32. Objective C Basics … @implementation Movie @synthesize name; - (NSString *) name { return name; } - (void) setName: (NSString *) movieName { if (![name isEqualToString: movieName]) { name = movieName; } } … @end Yahoo! Confidential 32
  • 33. Objective C Basics To sum up: NSString *name; - declares an instance variable 'name' @property (nonatomic, strong) NSString *name; - declares the accessor methods for 'name' @synthesize name; - implements the accessor methods for 'name' Yahoo! Confidential 33
  • 34. Objective C Basics Using strings (NSString class) NSString *movieName = @”Dhoom”; The @ symbol Ok, why does this funny @ sign show up all the time? Well, Objective-C is an extension of the C-language, which has its own ways to deal with strings. To differentiate the new type of strings, which are fully-fledged objects, Objective-C uses an @ sign. A new kind of string How does Objective-C improve on strings of the C language? Well, Objective-C strings are Unicode strings instead of ASCII strings. Unicode-strings can display characters of just about any language, such as Chinese, as well as the Roman alphabet. A C string is simply a series of characters (a one-dimensional character array) that is nullterminated, whereas an NSString object is a complete object with class methods, instance methods, etc. Note: It is possible (but not recommended) to use C language strings in Objective C. Yahoo! Confidential 34
  • 35. Objective C Basics Using ‘stringWithFormat’ NSString *movieName = [NSString stringWithFormat:@”Dhoom %d”, 2]; // Dhoom 2 Specifiers: %d %f %@ Signed 32-bit integer (int) 64-bit floating-point number (double) Objective-C object Complete list of format specifiers is available here. Introduction to NSLog NSLog(@”Movie name is %@”, movieName);     Format specifiers same as ‘stringWithFormat’. Used for debugging Same as error_log in PHP or console.log in JavaScript Note the use of round brackets unlike other method calls in objective C Yahoo! Confidential 35
  • 36. Objective C Basics Using arrays (NSArray class)  Provide random access  The objects contained in an array do not all have to be of the same type. Factory methods (static methods that build array from given parameters): + (id)array Creates and returns an empty array + (id)arrayWithObjects Creates and returns an array containing a given object Lot of such factory methods available Accessing the NSArray - (BOOL)containsObject:(id)anObject - (NSUInteger)count - (id)lastObject - (id)objectAtIndex:(NSUInteger)index Yahoo! Confidential Returns true if a given object is found in the array Returns the size of the array Returns the last object in the array Returns the object at a given index. 36
  • 37. Objective C Basics Introduction to NSMutableArray  NSArray is immutable (content of array cannot be modified without recreating it)  You can create mutable arrays (NSMutableArray) if you want to add or remove elements after creating. Additional functions to manipulate the array insertObject:atIndex: removeObjectAtIndex: addObject: removeLastObject replaceObjectAtIndex:withObject: Yahoo! Confidential 37
  • 38. Objective C Basics Introduction to NSDictionary  NSDictionary are like Maps and Hashes in other languages  Key-value pairs  It is an unordered collection of objects Factory methods (static methods that build array from given parameters): + (id)dictionary Creates and returns an empty dictionary + (id)dictionaryWithObjects: forKeys: Creates and returns a dictionary containing entries constructed from the contents of an array of keys and an array of values Lot of such factory methods available Accessing the NSDictionary – allKeys – allValues – objectForKey: Yahoo! Confidential Returns a new array containing the dictionary’s keys. Returns a new array containing the dictionary’s values. Returns the value associated with a given key. 38
  • 39. Objective C Basics Introduction to NSMutableDictionary  Similar to NSArray, NSDictionary is also immutable  You can create mutable dictionary (NSMutableDictionary) if you want to add or remove objects after creating. Additional functions to manipulate the dictionary setObject:forKey: removeObjectForKey: removeAllObjects: removeObjectsForKeys: Points to note:  NSArray and NSDictionary only store objects  So if you want to store numbers then you have to convert it to NSNumber  Use NSNull for empty values Yahoo! Confidential 39
  • 40. Topics  Getting Started  Introduction to Xcode and Application settings  Understanding App execution flow  Introduction to Objective-C  Writing your First iPhone Application  Introduction to Interface Builder  Outlets and Actions  Storyboards  Using the iPhone/iPad Simulator Yahoo! Confidential 40

Notes de l'éditeur

  1. Reference:http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/A_Tour_of_Xcode/010-Xcode_Features_Overview/FeaturesTake2.html#//apple_ref/doc/uid/TP30000890-CH220-SW3http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/RM_YourFirstApp_iOS/Articles/01_CreatingProject.html#//apple_ref/doc/uid/TP40011343-TP40012323-CH3-SW3
  2. Reference:http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
  3. Reference:https://developer.apple.com/library/mac/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/http://www.icodeblog.com/2009/06/18/objective-c-20-an-intro-part-1/