SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
iOS Programming - 101
Xcode, Obj-C, iOS APIs
Subhransu Behera
@subhransu
subh@subhb.org
Xcode
Development Tools
IB is built-in in Xcode 4

Xcode
IDE

Interface Builder
UI Design

iOS Simulator
Simulate Apps

Instruments
Monitor Performance
Xcode IDE

• Editors // source editor & UI editor
• Single window interface
• Automatic error identification and correction
• Assistance editing
• Source control
Navigation
area
Editor area

Debug area

Utility area
Run on Simulator or Device

Switch editors and views
Obj-C (Object Allocation)
Objective C
• Strict super set of C
• Provide Object Oriented Programming capability to C
• Dynamic Runtime.
• Message passing in stead of method calling
• Can mix-in C & C++ codes with Objective C
• Primary language used by Apple for Mac OSX and iOS
application development.
Objective C Class
#import <Foundation/Foundation.h>
@interface Cat : NSObject {
int numberOfEyes;
float lengthOfMyCat;

}

NSString *name;
NSString *breed;

-(void)drinkMilk;
-(void)makeACatDanceFor:(int)numberOfSeconds;
@end
• Class declaration starts at @interface and ends at
@end

• Cat is the class name that is the name after @interface
and before “:”

• NSObject is the name of the super-class
• numberOfEyes, lengthOfMyCat, name, breed are
attributes of a Class object.

• drinkMilk and makeACatDanceFor: are methods that a
an object of Cat (class) can respond to.
Object Allocation
Cat *myCat = [[Cat alloc] init];
// what exactly happens
// 1st line allocates enough memory to hold a cat object

Cat *myCat = [Cat alloc];
// 2nd line initializes the object.

[myCat init];
Message Passing
Message Passing in Obj-C
• In other languages you refer this as method calling.

But due to the nature of Obj-C it’s often referred as a
message (can refer it as method or function) being
passed to an object to make it do something.

• A message is passed to an object with-in square
brackets.

[objectName messageName];

• Messages can be piped together. That is a message
can be passed to an object is the result of another
message.
[[objectName messageOne] messageTwo];
Message Passing Syntax

The @implementation Sec

ny arguments. In Chapter 7,“More on Classes,” you’ll see how methods that take
than one argument are identified.

method
type

return
type

method
name

Figure 3.1

method
takes
argument

argument
type

argument
name

Declaring a method

@implementation Section

ed, the @implementation section contains the actual code for the methods you
ed in the @interface section.You have to specify what type of data is to be store
objects of this class.That is, you have to describe the data that members of the cl
Instance & Class Methods
• Instance responds to instance methods (starts with -)
-(id)init;
-(void)sing;
-(NSString *)description;

• Class responds to class methods (starts with +)
+(id)alloc;
+(void)initEventWithEventName:(NSString *)eventName
Message Passing

• [receiver message];
• [receiver message:argument];
• [receiver message:arg1 andArg:arg2];
Objective-C Properties
Declared Properties

• Provides a getter and a setter method
Manual Declaration without Properties
Refer to the SnailView.h and SnailView.m in SnailRun sample code

#import <UIKit/UIKit.h>
@interface SnailView : UIImageView {
double animationInterval;
NSString *snailName;
}
// manual declaration of methods
-(NSString *)getSnailName;
-(void)setSnailName:(NSString *)name;
@end
Manual Implementation without Properties
// manual getter method
-(NSString *)getSnailName {
return snailName;
}
// manual setter method
-(void)setSnailName:(NSString *)name {
if (![name isEqualToString:snailName]) {
snailName = name;
}
}
Doing it using Properties
@property (attributes) type name;

Atomicity
# atomic
# nonatomic

Writability, Ownership
# readonly
# strong, weak
Properties
@property (nonatomic, strong) NSString *snailName;
@property int animationInterval;
@property int animationInterval;
Core Obj-C Classes
Obj-C Classes
•
•
•
•
•

NSNumber, NSInteger
NSString, NSMutableString
NSArray, NSMutableArray
NSSet, NSMutableSet
NSDictionary, NSMutableDictionary
object vs mutable object
Mutable Object

Object

•
•

Readonly

•

However can be copied
to another mutable
object which can be
modified.

Original Object can not
be modified

•
•

Read-write
Can add, update, delete
original object
Strings
•

Have seen glimpse of it in all our NSLog
messages

•
•

NSLog(@"Objective C is Awesome");
NSString *snailName = [[NSString alloc] init];
Strings Methods
[NSString stringWithFormat:@"%d", someInteger];
[NSString stringWithFormat:@"My integer %d", someInteger];
[snailName stringByReplacingOccurrencesOfString:@"N"
withString:@"P"];
NSString *newString = [myString appendString:@"Another String"];
NSNumbers
NSNumber *animationDuration = [[NSNumber alloc] init];
NSNumber *animationDuration = [[NSNumber alloc]
initWithBool:YES];
NSNumber *animationDuration = [[NSNumber alloc]
initWithInt:1];
NSNumbers
// While creating NSNumbers
NSNumber *myNumber;
myNumber = @'Z';
myNumber = @YES;
myNumber = @1;
myNumber = @10.5;
// While evaluating expressions
NSNumber *myNewNumberAfterExpression = @(25 / 6);
NSArray & NSMutableArray
NSArray
(read-only)

•
•

Manage collections of Objects

•
•

NSMutableArray
(read write)

NSArray creates static array

Objects can be anything NSString, NSNumber, NSDictionary, even
NSArray itself.

NSMutableArray creates dynamic array

NSArray *myArray = [[NSArray alloc] init];
NSArray *myArray = [[NSArray alloc] initWithObjects:Obj1, Obj2, nil];
NSArray *myArray = @[Obj1, Obj2];
getting and setting values
•

Values are being accessed using array index

•
•

myArray[2] // will return 3rd object. Index starts from 0

Value can be set by assigning an Object for an index

•

myArray[3] = @"some value"; // will set value for 4th element
insertion & deletion
•

– count:

•
•

– containsObject:

•
•

Insert a given object at end of the array

– insertObject:atIndex:

•
•

Tells if a given object is present or not

– addObject:

•
•

returns number of objects currently in the array

Insert an object at specified index

– removeAllObjects:

•

Empties the array of all its elements
Learn more about
NSSet and NSDictionary
View Controllers
Key Objects in iOS Apps
Model
Data Model Objects
Data Model Objects
Data Model Objects

View

Controller

UIApplication

Application Delegate
(custom object)

UIWindow

Root View Controller
Event
Loop
Data Model Objects
Data ModelController
Additional Objects
Objects (custom)

Custom Objects
System Objects
Either system or custom objects

Data Model Objects
Data Model Objects
Views and UI Objects
when app finishes launching
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// window is being instantiated

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// view controller is being instantiated

self.viewController = [[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil];
// every app needs a window and a window needs a root view controller

self.window.rootViewController = self.viewController;

[self.window makeKeyAndVisible];
return YES;
}
what is this view controller
•

It is the controller part of M-V-C

•

Every view controller has a view

•

Your custom view controllers are sub-class of
UIViewController class.

•

Provides view-management model for your
apps.

•
•

Adjust the contents of views

•
•

Re-size views

Acts on-behalf of views when users
interacts!

Has view-event methods that gets called
when view appears and disappears!
View controller view events
•

– viewDidLoad:

•
•

– viewDidUnload:

•
•

When view is about to made visible

– viewDidAppear:

•
•

After view controller’s view is released or set to
nil

– viewWillAppear:

•
•

Called after view has been loaded

When view has been fully transitioned to screen

– viewWillDisappear: and – viewDidDisappear:

•

The counter-part of above 2 methods.
Managing View Rotations
•

– shouldAutoRotate

•
•
•

Whether auto-rotation is supported or not
Returns a boolean value YES/NO or TRUE/
FALSE

– supportedInterfaceOrientations

•
•

Returns interface orientation masks

– didRotateFromInterfaceOrientation

•

Notifies when rotation happens
Sample Codes
https://www.dropbox.com/s/wqcuusr9p2j913i/SampleCodes.zip

•
•
•
•
•
•

HelloWorld - Combines two text from text field and display on a label
SliderExample - Displays current value of a Slider
Hashes - Displays the number of hashes and creates a geometric structue
WeatherApp - Provides weather for a given day (hard coded values)
SnailRun - Makes a snail move in a direction (try changing the direction value)
MediaPlayer - Plays a local video file
To learn more ...
•
•

Objective C - Read Stephen Kochan’s Book

•
•
•

Play with Obj-C and iOS lessons from Code School

Go through “iOS UI Element Usage Guidelines” in iOS Human Interface
Guidelines to learn more about the various UI components available and their
usage

Watch iOS Development Videos & WWDC Videos
Join the community “iOS Dev Scout” facebook group.
Thanks

Subhransu Behera
@subhransu
subh@subhb.org

Mais conteúdo relacionado

Mais procurados

Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++HalaiHansaika
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cMayank Jalotra
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part IEugene Lazutkin
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in PythonJoshua Forman
 
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
 

Mais procurados (19)

Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
constructors and destructors in c++
constructors and destructors in c++constructors and destructors in c++
constructors and destructors in c++
 
Python - OOP Programming
Python - OOP ProgrammingPython - OOP Programming
Python - OOP Programming
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in Python
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
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
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3Object Oriented Programming using C++ - Part 3
Object Oriented Programming using C++ - Part 3
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 

Destaque

Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcodeSunny Shaikh
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework Eakapong Kattiya
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner GuideAndri Yadi
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS IntroductionPratik Vyas
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyondrsebbe
 
キーボードで完結!ハイスピード Xcodeコーディング
キーボードで完結!ハイスピード Xcodeコーディングキーボードで完結!ハイスピード Xcodeコーディング
キーボードで完結!ハイスピード Xcodeコーディングcocopon
 
iOS Hacking: Advanced Pentest & Forensic Techniques
iOS Hacking: Advanced Pentest & Forensic TechniquesiOS Hacking: Advanced Pentest & Forensic Techniques
iOS Hacking: Advanced Pentest & Forensic TechniquesÖmer Coşkun
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CDataArt
 

Destaque (19)

Advanced iOS
Advanced iOSAdvanced iOS
Advanced iOS
 
Introduction to xcode
Introduction to xcodeIntroduction to xcode
Introduction to xcode
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
iOS Basic Development Day 2 - Objective-C 2.0 & iOS Framework
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
iOS
iOSiOS
iOS
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner Guide
 
Apple iOS Introduction
Apple iOS IntroductionApple iOS Introduction
Apple iOS Introduction
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyond
 
キーボードで完結!ハイスピード Xcodeコーディング
キーボードで完結!ハイスピード Xcodeコーディングキーボードで完結!ハイスピード Xcodeコーディング
キーボードで完結!ハイスピード Xcodeコーディング
 
Ios operating system
Ios operating systemIos operating system
Ios operating system
 
200810 - iPhone Tutorial
200810 - iPhone Tutorial200810 - iPhone Tutorial
200810 - iPhone Tutorial
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
IELTS ORIENTATION
IELTS ORIENTATIONIELTS ORIENTATION
IELTS ORIENTATION
 
iOS Hacking: Advanced Pentest & Forensic Techniques
iOS Hacking: Advanced Pentest & Forensic TechniquesiOS Hacking: Advanced Pentest & Forensic Techniques
iOS Hacking: Advanced Pentest & Forensic Techniques
 
Никита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-CНикита Корчагин - Programming Apple iOS with Objective-C
Никита Корчагин - Programming Apple iOS with Objective-C
 

Semelhante a iOS 101 - Xcode, Objective-C, iOS APIs

Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4Edureka!
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-CKazunobu Tasaka
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's NewNascentDigital
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Manykenatmxm
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone developmentVonbo
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development IntroLuis Azevedo
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 

Semelhante a iOS 101 - Xcode, Objective-C, iOS APIs (20)

iOS testing
iOS testingiOS testing
iOS testing
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
2013-01-10 iOS testing
2013-01-10 iOS testing2013-01-10 iOS testing
2013-01-10 iOS testing
 
12Structures.pptx
12Structures.pptx12Structures.pptx
12Structures.pptx
 
Android webinar class_4
Android webinar class_4Android webinar class_4
Android webinar class_4
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
C#2
C#2C#2
C#2
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
Classes1
Classes1Classes1
Classes1
 
mean stack
mean stackmean stack
mean stack
 
iOS Development: What's New
iOS Development: What's NewiOS Development: What's New
iOS Development: What's New
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Day 1
Day 1Day 1
Day 1
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
Beginning to iPhone development
Beginning to iPhone developmentBeginning to iPhone development
Beginning to iPhone development
 
iPhone Development Intro
iPhone Development IntroiPhone Development Intro
iPhone Development Intro
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 

Último

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 

iOS 101 - Xcode, Objective-C, iOS APIs

  • 1. iOS Programming - 101 Xcode, Obj-C, iOS APIs Subhransu Behera @subhransu subh@subhb.org
  • 3. Development Tools IB is built-in in Xcode 4 Xcode IDE Interface Builder UI Design iOS Simulator Simulate Apps Instruments Monitor Performance
  • 4. Xcode IDE • Editors // source editor & UI editor • Single window interface • Automatic error identification and correction • Assistance editing • Source control
  • 5.
  • 7. Run on Simulator or Device Switch editors and views
  • 9. Objective C • Strict super set of C • Provide Object Oriented Programming capability to C • Dynamic Runtime. • Message passing in stead of method calling • Can mix-in C & C++ codes with Objective C • Primary language used by Apple for Mac OSX and iOS application development.
  • 10. Objective C Class #import <Foundation/Foundation.h> @interface Cat : NSObject { int numberOfEyes; float lengthOfMyCat; } NSString *name; NSString *breed; -(void)drinkMilk; -(void)makeACatDanceFor:(int)numberOfSeconds; @end
  • 11. • Class declaration starts at @interface and ends at @end • Cat is the class name that is the name after @interface and before “:” • NSObject is the name of the super-class • numberOfEyes, lengthOfMyCat, name, breed are attributes of a Class object. • drinkMilk and makeACatDanceFor: are methods that a an object of Cat (class) can respond to.
  • 12. Object Allocation Cat *myCat = [[Cat alloc] init]; // what exactly happens // 1st line allocates enough memory to hold a cat object Cat *myCat = [Cat alloc]; // 2nd line initializes the object. [myCat init];
  • 14. Message Passing in Obj-C • In other languages you refer this as method calling. But due to the nature of Obj-C it’s often referred as a message (can refer it as method or function) being passed to an object to make it do something. • A message is passed to an object with-in square brackets. [objectName messageName]; • Messages can be piped together. That is a message can be passed to an object is the result of another message. [[objectName messageOne] messageTwo];
  • 15. Message Passing Syntax The @implementation Sec ny arguments. In Chapter 7,“More on Classes,” you’ll see how methods that take than one argument are identified. method type return type method name Figure 3.1 method takes argument argument type argument name Declaring a method @implementation Section ed, the @implementation section contains the actual code for the methods you ed in the @interface section.You have to specify what type of data is to be store objects of this class.That is, you have to describe the data that members of the cl
  • 16. Instance & Class Methods • Instance responds to instance methods (starts with -) -(id)init; -(void)sing; -(NSString *)description; • Class responds to class methods (starts with +) +(id)alloc; +(void)initEventWithEventName:(NSString *)eventName
  • 17. Message Passing • [receiver message]; • [receiver message:argument]; • [receiver message:arg1 andArg:arg2];
  • 19. Declared Properties • Provides a getter and a setter method
  • 20. Manual Declaration without Properties Refer to the SnailView.h and SnailView.m in SnailRun sample code #import <UIKit/UIKit.h> @interface SnailView : UIImageView { double animationInterval; NSString *snailName; } // manual declaration of methods -(NSString *)getSnailName; -(void)setSnailName:(NSString *)name; @end
  • 21. Manual Implementation without Properties // manual getter method -(NSString *)getSnailName { return snailName; } // manual setter method -(void)setSnailName:(NSString *)name { if (![name isEqualToString:snailName]) { snailName = name; } }
  • 22. Doing it using Properties @property (attributes) type name; Atomicity # atomic # nonatomic Writability, Ownership # readonly # strong, weak
  • 23. Properties @property (nonatomic, strong) NSString *snailName; @property int animationInterval; @property int animationInterval;
  • 25. Obj-C Classes • • • • • NSNumber, NSInteger NSString, NSMutableString NSArray, NSMutableArray NSSet, NSMutableSet NSDictionary, NSMutableDictionary
  • 26. object vs mutable object Mutable Object Object • • Readonly • However can be copied to another mutable object which can be modified. Original Object can not be modified • • Read-write Can add, update, delete original object
  • 27. Strings • Have seen glimpse of it in all our NSLog messages • • NSLog(@"Objective C is Awesome"); NSString *snailName = [[NSString alloc] init];
  • 28. Strings Methods [NSString stringWithFormat:@"%d", someInteger]; [NSString stringWithFormat:@"My integer %d", someInteger]; [snailName stringByReplacingOccurrencesOfString:@"N" withString:@"P"]; NSString *newString = [myString appendString:@"Another String"];
  • 29. NSNumbers NSNumber *animationDuration = [[NSNumber alloc] init]; NSNumber *animationDuration = [[NSNumber alloc] initWithBool:YES]; NSNumber *animationDuration = [[NSNumber alloc] initWithInt:1];
  • 30. NSNumbers // While creating NSNumbers NSNumber *myNumber; myNumber = @'Z'; myNumber = @YES; myNumber = @1; myNumber = @10.5; // While evaluating expressions NSNumber *myNewNumberAfterExpression = @(25 / 6);
  • 31. NSArray & NSMutableArray NSArray (read-only) • • Manage collections of Objects • • NSMutableArray (read write) NSArray creates static array Objects can be anything NSString, NSNumber, NSDictionary, even NSArray itself. NSMutableArray creates dynamic array NSArray *myArray = [[NSArray alloc] init]; NSArray *myArray = [[NSArray alloc] initWithObjects:Obj1, Obj2, nil]; NSArray *myArray = @[Obj1, Obj2];
  • 32. getting and setting values • Values are being accessed using array index • • myArray[2] // will return 3rd object. Index starts from 0 Value can be set by assigning an Object for an index • myArray[3] = @"some value"; // will set value for 4th element
  • 33. insertion & deletion • – count: • • – containsObject: • • Insert a given object at end of the array – insertObject:atIndex: • • Tells if a given object is present or not – addObject: • • returns number of objects currently in the array Insert an object at specified index – removeAllObjects: • Empties the array of all its elements
  • 34. Learn more about NSSet and NSDictionary
  • 36. Key Objects in iOS Apps Model Data Model Objects Data Model Objects Data Model Objects View Controller UIApplication Application Delegate (custom object) UIWindow Root View Controller Event Loop Data Model Objects Data ModelController Additional Objects Objects (custom) Custom Objects System Objects Either system or custom objects Data Model Objects Data Model Objects Views and UI Objects
  • 37. when app finishes launching - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // window is being instantiated self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // view controller is being instantiated self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; // every app needs a window and a window needs a root view controller self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
  • 38. what is this view controller • It is the controller part of M-V-C • Every view controller has a view • Your custom view controllers are sub-class of UIViewController class. • Provides view-management model for your apps. • • Adjust the contents of views • • Re-size views Acts on-behalf of views when users interacts! Has view-event methods that gets called when view appears and disappears!
  • 39. View controller view events • – viewDidLoad: • • – viewDidUnload: • • When view is about to made visible – viewDidAppear: • • After view controller’s view is released or set to nil – viewWillAppear: • • Called after view has been loaded When view has been fully transitioned to screen – viewWillDisappear: and – viewDidDisappear: • The counter-part of above 2 methods.
  • 40. Managing View Rotations • – shouldAutoRotate • • • Whether auto-rotation is supported or not Returns a boolean value YES/NO or TRUE/ FALSE – supportedInterfaceOrientations • • Returns interface orientation masks – didRotateFromInterfaceOrientation • Notifies when rotation happens
  • 41. Sample Codes https://www.dropbox.com/s/wqcuusr9p2j913i/SampleCodes.zip • • • • • • HelloWorld - Combines two text from text field and display on a label SliderExample - Displays current value of a Slider Hashes - Displays the number of hashes and creates a geometric structue WeatherApp - Provides weather for a given day (hard coded values) SnailRun - Makes a snail move in a direction (try changing the direction value) MediaPlayer - Plays a local video file
  • 42. To learn more ... • • Objective C - Read Stephen Kochan’s Book • • • Play with Obj-C and iOS lessons from Code School Go through “iOS UI Element Usage Guidelines” in iOS Human Interface Guidelines to learn more about the various UI components available and their usage Watch iOS Development Videos & WWDC Videos Join the community “iOS Dev Scout” facebook group.