SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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 Kamlesh Makvana
 
.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)David McCarter
 
An Objective-C Primer
An Objective-C PrimerAn Objective-C Primer
An Objective-C PrimerBabul Mirdha
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#Alfonso Garcia-Caro
 
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 CDTElena Laskavaia
 
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 RESTNicolas Faugout
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#Svetlin Nakov
 
PhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginPhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginHaehnchen
 
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 & objectsRai University
 
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTCode Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTdschaefer
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questionsadarshynl
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphismFALLEE31188
 
#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 StructureHadziq Fabroyir
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred CowsKevlin Henney
 
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 6Ray Ploski
 
How to Profit from Static Analysis
How to Profit from Static AnalysisHow to Profit from Static Analysis
How to Profit from Static AnalysisElena Laskavaia
 

What's hot (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
 

Viewers also liked

2011 iOS & Android 市場數據報告
2011 iOS & Android 市場數據報告2011 iOS & Android 市場數據報告
2011 iOS & Android 市場數據報告Faust Li
 
iPhone application development training day 1
iPhone application development training day 1iPhone application development training day 1
iPhone application development training day 1Shyamala Prayaga
 
Training Session iOS UI Guidelines
Training Session iOS UI GuidelinesTraining Session iOS UI Guidelines
Training Session iOS UI GuidelinesE2LOGY
 
Introduction to iOS Apps Development
Introduction to iOS Apps DevelopmentIntroduction to iOS Apps Development
Introduction to iOS Apps DevelopmentProf. Erwin Globio
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS IntroductionPratik Vyas
 

Viewers also liked (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
 

Similar to iOS training (basic)

iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
 
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)Oliver Lin
 
Objective c beginner's guide
Objective c beginner's guideObjective c beginner's guide
Objective c beginner's guideTiago Faller
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
Presentation1 password
Presentation1 passwordPresentation1 password
Presentation1 passwordAnkit Desai
 
I Phone Development Presentation
I Phone Development PresentationI Phone Development Presentation
I Phone Development PresentationAessam
 
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) Mobivery
 
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.pdfShaiAlmog1
 
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 cBilly Abbott
 
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-slidesSami Mut
 
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.pdfShaiAlmog1
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworksMD Sayem Ahmed
 
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
 

Similar to 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
 

More from Gurpreet Singh Sachdeva

More from 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
 

Recently uploaded

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
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.pptxAreebaZafar22
 
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).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
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.christianmathematics
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
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.pdfAdmir Softic
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
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
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.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
 

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

Editor's Notes

  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/