SlideShare una empresa de Scribd logo
1 de 61
Descargar para leer sin conexión
Beginning iOS
                       Development

                             http://bobmccune.com




Monday, March 19, 12
Agenda
                Beginning iOS Development
                       • Understanding the Tools
                       • Objective-C Crash Course
                       • Using Cocoa Touch




Monday, March 19, 12
iOS SDK Tools


Monday, March 19, 12
Xcode




Monday, March 19, 12
Xcode
              • Apple’s IDE for creating Mac and iOS apps
              • Provides visual front end to LLVM and LLDB
              • Hub of development process:
                       Editing               UI Design
                       Building              Testing
                       Refactoring           Model Design
                       Debugging             Deployment
                       API Doc Integration   Project Configuration


Monday, March 19, 12
iOS Simulator




Monday, March 19, 12
iOS Simulator
              • Device simulator, runs on your desktop
                 • Both iPhone and iPad (retina, non-retina)
                 • Faster code, build, test cycle
                 • Test behaviors: rotation, shake, multi-touch
                 • Easier testing of exceptional conditions
              • iOS Simulator != iOS Device:
                 • No memory or CPU limits
                 • Not all APIs and capabilities available
Monday, March 19, 12
Instruments




Monday, March 19, 12
Instruments

             • Dynamic tracing and profiling tool
             • Uses digital audio workstation-like interface
             • Large library of standard instruments
                   • Core Animation, Leaks, Automation, etc.
                   • The ultra geeky can build custom instruments




Monday, March 19, 12
Hands-On Tour


Monday, March 19, 12
Objective-C



Monday, March 19, 12
Agenda
                Objective-C Essentials
                       •   Overview of Objective-C
                       •   Understanding Classes and Objects
                       •   Methods, Messages, and Properties
                       •   Protocols




Monday, March 19, 12
Objective-C
                The old, new hotness
                  • Strict superset of ANSI C
                       • Object-oriented extensions
                       • Additional syntax and types
                  • Dynamic, Object-Oriented Language:
                       • Dynamic Typing
                       • Dynamic Binding
                       • Dynamic Loading



Monday, March 19, 12
Creating Classes



Monday, March 19, 12
Creating Classes
                The Blueprint
                       • Objective-C classes are separated into an
                        interface and an implementation.
                         • Usually defined in separate .h and .m files

                                  •Defines the            •Defines the actual
                                   programming            implementation
                                   interface              code

                                  •Can define
                                   object instance       •Implement one or
                                   variables              more initializers to
                                                          properly initialize
                                                          an object instance




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Interface
                 @interface BankAccount : NSObject {
                 	 float accountBalance;
                 	 NSString *accountNumber;
                 }

                  - (float)withDraw:(float)amount;
                  - (void)deposit:(float)amount;
                 @end




Monday, March 19, 12
Defining the Implementation
                   #import "BankAccount.h"

                   @implementation BankAccount

                   - (id)init {
                   	 self = [super init];
                   	 return self;
                   }

                   - (float)withdraw:(float)amount {
                   	 // calculate valid withdrawal
                   	 return amount;
                   }

                   - (void)deposit:(float)amount {
                        // record transaction
                   }
                   @end


Monday, March 19, 12
Defining the Implementation
                   #import "BankAccount.h"

                   @implementation BankAccount

                   - (id)init {
                   	 self = [super init];
                   	 return self;
                   }

                   - (float)withdraw:(float)amount {
                   	 // calculate valid withdrawal
                   	 return amount;
                   }

                   - (void)deposit:(float)amount {
                        // record transaction
                   }
                   @end


Monday, March 19, 12
Defining the Implementation
                   #import "BankAccount.h"

                   @implementation BankAccount

                   - (id)init {
                   	 self = [super init];
                   	 return self;
                   }

                   - (float)withdraw:(float)amount {
                   	 // calculate valid withdrawal
                   	 return amount;
                   }

                   - (void)deposit:(float)amount {
                        // record transaction
                   }
                   @end


Monday, March 19, 12
Defining the Implementation
                   #import "BankAccount.h"

                   @implementation BankAccount

                   - (id)init {
                   	 self = [super init];
                   	 return self;
                   }

                   - (float)withdraw:(float)amount {
                   	 // calculate valid withdrawal
                   	 return amount;
                   }

                   - (void)deposit:(float)amount {
                        // record transaction
                   }
                   @end


Monday, March 19, 12
Defining Methods
                Understanding the Syntax
                       • Class methods
                         • Prefixed with a +
                         • Tied to class, not instance
                       • Instance Methods
                         • Instance methods prefix with a -
                         • Modifies state of an object instance

                            - (NSString *)description;




Monday, March 19, 12
Defining Methods
                Understanding the Syntax
                       • Class methods
                         • Prefixed with a +
                         • Tied to class, not instance
                       • Instance Methods
                         • Instance methods prefix with a -
                         • Modifies state of an object instance

               - (BOOL)respondsToSelector:(SEL)aSelector;




Monday, March 19, 12
Defining Methods
                Understanding the Syntax
                       • Class methods
                         • Prefixed with a +
                         • Tied to class, not instance
                       • Instance Methods
                         • Instance methods prefix with a -
                         • Modifies state of an object instance
               + (void)transitionWithView:(UIView *)view
                                 duration:(NSTimeInterval)duration
                                  options:(UIViewAnimationOptions)options
                               animations:(void (^)(void))animations
                               completion:(void (^)(BOOL finished))completion;



Monday, March 19, 12
self and super
                Talking to yourself
                       • Methods have implicit reference to owning
                         object called self
                       • Additionally have access to superclass
                         methods using super
                        -(id)init {
                            self = [super init];
                            if (self) {
                                // do initialization
                            }
                            return self;
                        }

Monday, March 19, 12
Working with Objects



Monday, March 19, 12
Two-Stage Creation
                • NSObject defines class method called alloc
                       • Dynamically allocates memory for object
                       • Returns new instance of receiving class
                       BankAccount *account = [BankAccount alloc];

               • NSObject defines instance method init
                       • Implemented by subclasses to initialize instance after memory
                         for it has been allocated
                       • Subclasses commonly define several initializers
                         account = [account init];

                •      alloc   and init calls should always nested into single line
                       BankAccount *account = [[BankAccount alloc] init];



Monday, March 19, 12
Messages
                Communicating with Objects
                       • Methods are invoked by passing messages
                         • Methods are never directly invoked
                         • Messages dynamically bound to method
                             implementations at runtime
                       • Simple messages take the form:
                         •




                             [object message];

                       • Can pass one or more arguments:
                         •




                             [object methodWithArg1:arg1 arg2:arg2];




Monday, March 19, 12
Messaging an Object
                NSMutableDictionary *person =
                     [NSMutableDictionary dictionary];

                [person setObject:@"Joe Smith" forKey:@"name"];

                NSString *address = @"123 Street";
                NSString *house =
                    [address substringWithRange:NSMakeRange(0, 3)];
                [person setObject:house forKey:@"houseNumber"];

                NSArray *children =
                   [NSArray arrayWithObjects:@"Jack", @"Susie", nil];

               [person setObject:children forKey:@"children"];




Monday, March 19, 12
Declared Properties



Monday, March 19, 12
Declared Properties
                Simplifying Accessors
                  • Most common methods we write are accessors
                  • Objective-C can automatically generate accessors
                       • Much less verbose, less error prone
                       • Highly configurable
                  • Declared properties are defined in two parts:
                       • @property definition in the interface
                       • @synthesize statement in the implementation




Monday, March 19, 12
Declaring Properties
               @property (attributes) type variable;

                         Attribute      Impacts
                         nonatomic     Concurrency

                 readonly/readwrite     Mutability

                       strong/copy/
                                         Storage
                       weak/assign

                       getter/setter       API



Monday, March 19, 12
Declaring Properties
               @property (attributes) type variable;

                         Attribute          Impacts
                         nonatomic        Concurrency

                 readonly/readwrite        Mutability

                       strong/copy/
                                            Storage
                       weak/assign

                       getter/setter          API

                       @property (readonly) BOOL active;
Monday, March 19, 12
Declaring Properties
               @property (attributes) type variable;

                         Attribute      Impacts
                         nonatomic     Concurrency

                 readonly/readwrite     Mutability

                       strong/copy/
                                         Storage
                       weak/assign

                       getter/setter       API

              @property (nonatomic, readonly) BOOL active;

Monday, March 19, 12
Declaring Properties
               @property (attributes) type variable;

                         Attribute      Impacts
                         nonatomic     Concurrency

                 readonly/readwrite     Mutability

                       strong/copy/
                                         Storage
                       weak/assign

                       getter/setter       API

            @property (nonatomic, strong) NSDate *activeDate;

Monday, March 19, 12
Declaring Properties
               @property (attributes) type variable;

                         Attribute        Impacts
                         nonatomic       Concurrency

                 readonly/readwrite       Mutability

                       strong/copy/
                                           Storage
                       weak/assign

                       getter/setter         API

              @property (readonly, getter=isValid) BOOL valid;

Monday, March 19, 12
Declaring Properties
                Defining the Interface

                @interface BankAccount : NSObject

                @property   (nonatomic, copy) NSString *accountNumber;
                @property   (nonatomic, strong) NSDecimalNumber *balance;
                @property   (readonly, strong) NSDecimalNumber *fees;
                @property   (getter=isCurrent) BOOL accountCurrent;

                @end




Monday, March 19, 12
Synthesizing Properties
                Generating the Accessors

                @implementation BankAccount

                @synthesize   accountNumber = _accountNumber;
                @synthesize   balance = _balance;
                @synthesize   fees = _fees;
                @synthesize   accountCurrent = _accountCurrent;

                @end




Monday, March 19, 12
Accessing Properties
                       • Generated properties are standard methods
                       • Accessed through normal messaging syntax
                        [object property];
                        [object setProperty:newValue];

                       • Objective-C property access via dot notation
                        object.property;
                        object.property = newValue;


                        Dot notation is just syntactic sugar. Still uses accessor
                        methods. Doesn't get/set values directly.

Monday, March 19, 12
Protocols



Monday, March 19, 12
Protocols
                Object-Oriented Contracts
                       • Abstract methods to be implemented
                         • Methods are not tied to a specific class
                         • Analogous to C# and Java interfaces
                       • Useful in defining:
                         • Capturing similarities among classes that aren't
                             hierarchically related
                         •   Declaring an interface while hiding its particular
                             class
                         •   Delegate callback methods




Monday, March 19, 12
Defining a Protocol
                NSCoding
                * NSCoding defined in Foundation Framework

                @protocol NSCoding

                - (void)encodeWithCoder:(NSCoder *)aCoder;
                - (id)initWithCoder:(NSCoder *)aDecoder;

                @end




Monday, March 19, 12
Adopting a Protocol
                Conforming to the Contract

                @interface User : NSObject <NSCoding>

                @property (nonatomic, copy) NSString *username;
                @property (nonatomic, copy) NSString *password;

                @end




Monday, March 19, 12
Adopting a Protocol
                Conforming to the Contract

                @interface User : NSObject <NSCoding>

                @property (nonatomic, copy) NSString *username;
                @property (nonatomic, copy) NSString *password;

                @end




Monday, March 19, 12
Adopting a Protocol
                 Conforming to the Contract
                 @implementation User

                 -(id)initWithCoder:(NSCoder *)coder {
                 	 if (self = [super init]) {
                 	 	 self.username = [coder decodeObjectForKey:@"username"];
                 	 	 self.password = [coder decodeObjectForKey:@"password"];
                 	 }
                 	 return self;
                 }

                 -(void)encodeWithCoder:(NSCoder *)coder {
                 	 [coder encodeObject:self.username forKey:@"username"];
                 	 [coder encodeObject:self.username forKey:@"password"];
                 }

                 @end


Monday, March 19, 12
Time to Code!



Monday, March 19, 12
Using Cocoa Touch




Monday, March 19, 12
Cocoa Touch
               Foundation Framework

                   • Core framework for non-UI functionality
                   • Operating System Classes
                       • threading, archiving, filesystem
                   • Collections
                       • Common collection types: arrays, dictionaries, sets
                   • Networking support
                   • XML Processing



Monday, March 19, 12
Cocoa Touch
               UIKit Framework

                   • Framework for building iOS user interfaces
                   • User Interface Elements
                     • Tables, buttons, images, etc.
                   • Views and View Controllers
                   • Multitouch Event Handling
                   • High-level Drawing Routines




Monday, March 19, 12
Understanding MVC
                Model,View, Controller



                       Model                  View




                                 Controller




Monday, March 19, 12
UIView
                The “V” in MVC
                       • Base class for iOS user interface components
                         • Drawing and animation
                         • Layout and subview management
                         • Multitouch event handling
                       • Xcode’s Interface Builder used to build UI
                         • Archived version of UI stored in XIB/NIB file
                         • Dynamically loaded at runtime by controller
                       • Can be created programmatically


Monday, March 19, 12
UIViewController
                The “C” in MVC
                • The heart of every iOS app
                • Provides the “glue code” between the model
                  and view
                • Responsible for managing the view hierarchy
                  and lifecycle
                • Key view lifecycle methods:
                       - (void)loadView;
                       - (void)viewDidLoad;
                       - (void)viewDidUnload;



Monday, March 19, 12
UIViewController: View Loading
           controller.view



             View Controller

                              Is view nil?

                       View                  loadView       viewDidLoad


                                   1) Overridden
                                   2) Loaded from NIB
                                   3) Return empty UIView


Monday, March 19, 12
View Unloading
                Dealing with low memory conditions
                       • didReceiveMemoryWarning
                         • Called by OS when low memory encountered
                         • If possible, will release controller’s view
                         • Can override, but must call super
                       • viewDidUnload invoked if root view released
                         • Override to release anything that can be
                           recreated in loadView/viewDidLoad




Monday, March 19, 12
Display-related Callbacks
                       viewWillAppear
                        • Called immediately prior to being presented
                       viewDidAppear
                        • Called upon view being added to window
                       viewWillDisappear
                        • Called immediately before view is removed
                          from window or is covered by another view
                       viewDidDisappear
                        • Called after view is removed from window or
                          is covered by another view


Monday, March 19, 12
Outlets and Actions
                Wiring the View and View Controller
                       • Provides metadata to Interface Builder to
                         allow connections between objects
                       • IBOutlet
                          • Property reference to XIB/NIB objects
                          • Null-defined C macro
                       • IBAction
                          • Used by Interface Builder to determine available
                             actions
                         •   Void-defined C macro




Monday, March 19, 12
Time to Code!



Monday, March 19, 12

Más contenido relacionado

Similar a Beginningi os part1-bobmccune

Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Altece
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesEdgar Gonzalez
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shinyanamarisaguedes
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOSPetr Dvorak
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPACheng Ta Yeh
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsPetr Dvorak
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language鍾誠 陳鍾誠
 
Rust Cologne/Bonn Meetup 29.07.2015
Rust Cologne/Bonn Meetup 29.07.2015Rust Cologne/Bonn Meetup 29.07.2015
Rust Cologne/Bonn Meetup 29.07.2015Harris Brakmic
 
iOS overview
iOS overviewiOS overview
iOS overviewgupta25
 
Improving application design with a rich domain model (springone 2007)
Improving application design with a rich domain model (springone 2007)Improving application design with a rich domain model (springone 2007)
Improving application design with a rich domain model (springone 2007)Chris Richardson
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's DiveAltece
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom UsageJoshua Long
 
Swift on Raspberry Pi
Swift on Raspberry PiSwift on Raspberry Pi
Swift on Raspberry PiSally Shepard
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 

Similar a Beginningi os part1-bobmccune (20)

Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and Techniques
 
Introduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R ShinyIntroduction to interactive data visualisation using R Shiny
Introduction to interactive data visualisation using R Shiny
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
Day 1
Day 1Day 1
Day 1
 
Lecture 09 high level language
Lecture 09 high level languageLecture 09 high level language
Lecture 09 high level language
 
Rust Cologne/Bonn Meetup 29.07.2015
Rust Cologne/Bonn Meetup 29.07.2015Rust Cologne/Bonn Meetup 29.07.2015
Rust Cologne/Bonn Meetup 29.07.2015
 
iOS overview
iOS overviewiOS overview
iOS overview
 
Improving application design with a rich domain model (springone 2007)
Improving application design with a rich domain model (springone 2007)Improving application design with a rich domain model (springone 2007)
Improving application design with a rich domain model (springone 2007)
 
Objective-C A Beginner's Dive
Objective-C A Beginner's DiveObjective-C A Beginner's Dive
Objective-C A Beginner's Dive
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Swift on Raspberry Pi
Swift on Raspberry PiSwift on Raspberry Pi
Swift on Raspberry Pi
 
Android overview
Android overviewAndroid overview
Android overview
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve Mobile
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 

Más de Mobile March

Cross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince BullingerCross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince BullingerMobile March
 
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...Mobile March
 
Building Wearables-Kristina Durivage
Building Wearables-Kristina DurivageBuilding Wearables-Kristina Durivage
Building Wearables-Kristina DurivageMobile March
 
The Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-SparkThe Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-SparkMobile March
 
LiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel GerdeenLiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel GerdeenMobile March
 
The Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew DavidThe Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew DavidMobile March
 
Unity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh RuisUnity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh RuisMobile March
 
IP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest GrumblesIP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest GrumblesMobile March
 
Using Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott LembckeUsing Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott LembckeMobile March
 
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt PrinsUsing Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt PrinsMobile March
 
Introduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroIntroduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroMobile March
 
Developing Custom iOs Applications for Enterprise
Developing Custom iOs Applications for EnterpriseDeveloping Custom iOs Applications for Enterprise
Developing Custom iOs Applications for EnterpriseMobile March
 
Product Management for Your App
Product Management for Your AppProduct Management for Your App
Product Management for Your AppMobile March
 
Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication Mobile March
 
Guy Thier Keynote Presentation
Guy Thier Keynote PresentationGuy Thier Keynote Presentation
Guy Thier Keynote PresentationMobile March
 
Mobile March Olson presentation 2012
Mobile March Olson presentation 2012Mobile March Olson presentation 2012
Mobile March Olson presentation 2012Mobile March
 
Bannin mobile march_2012_public
Bannin mobile march_2012_publicBannin mobile march_2012_public
Bannin mobile march_2012_publicMobile March
 
Mobile march2012 android101-pt2
Mobile march2012 android101-pt2Mobile march2012 android101-pt2
Mobile march2012 android101-pt2Mobile March
 
Mobile march2012 android101-pt1
Mobile march2012 android101-pt1Mobile march2012 android101-pt1
Mobile march2012 android101-pt1Mobile March
 

Más de Mobile March (20)

Cross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince BullingerCross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince Bullinger
 
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
 
Building Wearables-Kristina Durivage
Building Wearables-Kristina DurivageBuilding Wearables-Kristina Durivage
Building Wearables-Kristina Durivage
 
The Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-SparkThe Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-Spark
 
LiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel GerdeenLiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel Gerdeen
 
The Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew DavidThe Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew David
 
Unity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh RuisUnity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh Ruis
 
IP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest GrumblesIP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest Grumbles
 
Using Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott LembckeUsing Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott Lembcke
 
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt PrinsUsing Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
 
Introduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroIntroduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason Shapiro
 
Developing Custom iOs Applications for Enterprise
Developing Custom iOs Applications for EnterpriseDeveloping Custom iOs Applications for Enterprise
Developing Custom iOs Applications for Enterprise
 
Product Management for Your App
Product Management for Your AppProduct Management for Your App
Product Management for Your App
 
Robotium Tutorial
Robotium TutorialRobotium Tutorial
Robotium Tutorial
 
Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication
 
Guy Thier Keynote Presentation
Guy Thier Keynote PresentationGuy Thier Keynote Presentation
Guy Thier Keynote Presentation
 
Mobile March Olson presentation 2012
Mobile March Olson presentation 2012Mobile March Olson presentation 2012
Mobile March Olson presentation 2012
 
Bannin mobile march_2012_public
Bannin mobile march_2012_publicBannin mobile march_2012_public
Bannin mobile march_2012_public
 
Mobile march2012 android101-pt2
Mobile march2012 android101-pt2Mobile march2012 android101-pt2
Mobile march2012 android101-pt2
 
Mobile march2012 android101-pt1
Mobile march2012 android101-pt1Mobile march2012 android101-pt1
Mobile march2012 android101-pt1
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Beginningi os part1-bobmccune

  • 1. Beginning iOS Development http://bobmccune.com Monday, March 19, 12
  • 2. Agenda Beginning iOS Development • Understanding the Tools • Objective-C Crash Course • Using Cocoa Touch Monday, March 19, 12
  • 3. iOS SDK Tools Monday, March 19, 12
  • 5. Xcode • Apple’s IDE for creating Mac and iOS apps • Provides visual front end to LLVM and LLDB • Hub of development process: Editing UI Design Building Testing Refactoring Model Design Debugging Deployment API Doc Integration Project Configuration Monday, March 19, 12
  • 7. iOS Simulator • Device simulator, runs on your desktop • Both iPhone and iPad (retina, non-retina) • Faster code, build, test cycle • Test behaviors: rotation, shake, multi-touch • Easier testing of exceptional conditions • iOS Simulator != iOS Device: • No memory or CPU limits • Not all APIs and capabilities available Monday, March 19, 12
  • 9. Instruments • Dynamic tracing and profiling tool • Uses digital audio workstation-like interface • Large library of standard instruments • Core Animation, Leaks, Automation, etc. • The ultra geeky can build custom instruments Monday, March 19, 12
  • 12. Agenda Objective-C Essentials • Overview of Objective-C • Understanding Classes and Objects • Methods, Messages, and Properties • Protocols Monday, March 19, 12
  • 13. Objective-C The old, new hotness • Strict superset of ANSI C • Object-oriented extensions • Additional syntax and types • Dynamic, Object-Oriented Language: • Dynamic Typing • Dynamic Binding • Dynamic Loading Monday, March 19, 12
  • 15. Creating Classes The Blueprint • Objective-C classes are separated into an interface and an implementation. • Usually defined in separate .h and .m files •Defines the •Defines the actual programming implementation interface code •Can define object instance •Implement one or variables more initializers to properly initialize an object instance Monday, March 19, 12
  • 16. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 17. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 18. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 19. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 20. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 21. Defining the Interface @interface BankAccount : NSObject { float accountBalance; NSString *accountNumber; } - (float)withDraw:(float)amount; - (void)deposit:(float)amount; @end Monday, March 19, 12
  • 22. Defining the Implementation #import "BankAccount.h" @implementation BankAccount - (id)init { self = [super init]; return self; } - (float)withdraw:(float)amount { // calculate valid withdrawal return amount; } - (void)deposit:(float)amount { // record transaction } @end Monday, March 19, 12
  • 23. Defining the Implementation #import "BankAccount.h" @implementation BankAccount - (id)init { self = [super init]; return self; } - (float)withdraw:(float)amount { // calculate valid withdrawal return amount; } - (void)deposit:(float)amount { // record transaction } @end Monday, March 19, 12
  • 24. Defining the Implementation #import "BankAccount.h" @implementation BankAccount - (id)init { self = [super init]; return self; } - (float)withdraw:(float)amount { // calculate valid withdrawal return amount; } - (void)deposit:(float)amount { // record transaction } @end Monday, March 19, 12
  • 25. Defining the Implementation #import "BankAccount.h" @implementation BankAccount - (id)init { self = [super init]; return self; } - (float)withdraw:(float)amount { // calculate valid withdrawal return amount; } - (void)deposit:(float)amount { // record transaction } @end Monday, March 19, 12
  • 26. Defining Methods Understanding the Syntax • Class methods • Prefixed with a + • Tied to class, not instance • Instance Methods • Instance methods prefix with a - • Modifies state of an object instance - (NSString *)description; Monday, March 19, 12
  • 27. Defining Methods Understanding the Syntax • Class methods • Prefixed with a + • Tied to class, not instance • Instance Methods • Instance methods prefix with a - • Modifies state of an object instance - (BOOL)respondsToSelector:(SEL)aSelector; Monday, March 19, 12
  • 28. Defining Methods Understanding the Syntax • Class methods • Prefixed with a + • Tied to class, not instance • Instance Methods • Instance methods prefix with a - • Modifies state of an object instance + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; Monday, March 19, 12
  • 29. self and super Talking to yourself • Methods have implicit reference to owning object called self • Additionally have access to superclass methods using super -(id)init { self = [super init]; if (self) { // do initialization } return self; } Monday, March 19, 12
  • 31. Two-Stage Creation • NSObject defines class method called alloc • Dynamically allocates memory for object • Returns new instance of receiving class BankAccount *account = [BankAccount alloc]; • NSObject defines instance method init • Implemented by subclasses to initialize instance after memory for it has been allocated • Subclasses commonly define several initializers account = [account init]; • alloc and init calls should always nested into single line BankAccount *account = [[BankAccount alloc] init]; Monday, March 19, 12
  • 32. Messages Communicating with Objects • Methods are invoked by passing messages • Methods are never directly invoked • Messages dynamically bound to method implementations at runtime • Simple messages take the form: • [object message]; • Can pass one or more arguments: • [object methodWithArg1:arg1 arg2:arg2]; Monday, March 19, 12
  • 33. Messaging an Object NSMutableDictionary *person = [NSMutableDictionary dictionary]; [person setObject:@"Joe Smith" forKey:@"name"]; NSString *address = @"123 Street"; NSString *house = [address substringWithRange:NSMakeRange(0, 3)]; [person setObject:house forKey:@"houseNumber"]; NSArray *children = [NSArray arrayWithObjects:@"Jack", @"Susie", nil]; [person setObject:children forKey:@"children"]; Monday, March 19, 12
  • 35. Declared Properties Simplifying Accessors • Most common methods we write are accessors • Objective-C can automatically generate accessors • Much less verbose, less error prone • Highly configurable • Declared properties are defined in two parts: • @property definition in the interface • @synthesize statement in the implementation Monday, March 19, 12
  • 36. Declaring Properties @property (attributes) type variable; Attribute Impacts nonatomic Concurrency readonly/readwrite Mutability strong/copy/ Storage weak/assign getter/setter API Monday, March 19, 12
  • 37. Declaring Properties @property (attributes) type variable; Attribute Impacts nonatomic Concurrency readonly/readwrite Mutability strong/copy/ Storage weak/assign getter/setter API @property (readonly) BOOL active; Monday, March 19, 12
  • 38. Declaring Properties @property (attributes) type variable; Attribute Impacts nonatomic Concurrency readonly/readwrite Mutability strong/copy/ Storage weak/assign getter/setter API @property (nonatomic, readonly) BOOL active; Monday, March 19, 12
  • 39. Declaring Properties @property (attributes) type variable; Attribute Impacts nonatomic Concurrency readonly/readwrite Mutability strong/copy/ Storage weak/assign getter/setter API @property (nonatomic, strong) NSDate *activeDate; Monday, March 19, 12
  • 40. Declaring Properties @property (attributes) type variable; Attribute Impacts nonatomic Concurrency readonly/readwrite Mutability strong/copy/ Storage weak/assign getter/setter API @property (readonly, getter=isValid) BOOL valid; Monday, March 19, 12
  • 41. Declaring Properties Defining the Interface @interface BankAccount : NSObject @property (nonatomic, copy) NSString *accountNumber; @property (nonatomic, strong) NSDecimalNumber *balance; @property (readonly, strong) NSDecimalNumber *fees; @property (getter=isCurrent) BOOL accountCurrent; @end Monday, March 19, 12
  • 42. Synthesizing Properties Generating the Accessors @implementation BankAccount @synthesize accountNumber = _accountNumber; @synthesize balance = _balance; @synthesize fees = _fees; @synthesize accountCurrent = _accountCurrent; @end Monday, March 19, 12
  • 43. Accessing Properties • Generated properties are standard methods • Accessed through normal messaging syntax [object property]; [object setProperty:newValue]; • Objective-C property access via dot notation object.property; object.property = newValue; Dot notation is just syntactic sugar. Still uses accessor methods. Doesn't get/set values directly. Monday, March 19, 12
  • 45. Protocols Object-Oriented Contracts • Abstract methods to be implemented • Methods are not tied to a specific class • Analogous to C# and Java interfaces • Useful in defining: • Capturing similarities among classes that aren't hierarchically related • Declaring an interface while hiding its particular class • Delegate callback methods Monday, March 19, 12
  • 46. Defining a Protocol NSCoding * NSCoding defined in Foundation Framework @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; - (id)initWithCoder:(NSCoder *)aDecoder; @end Monday, March 19, 12
  • 47. Adopting a Protocol Conforming to the Contract @interface User : NSObject <NSCoding> @property (nonatomic, copy) NSString *username; @property (nonatomic, copy) NSString *password; @end Monday, March 19, 12
  • 48. Adopting a Protocol Conforming to the Contract @interface User : NSObject <NSCoding> @property (nonatomic, copy) NSString *username; @property (nonatomic, copy) NSString *password; @end Monday, March 19, 12
  • 49. Adopting a Protocol Conforming to the Contract @implementation User -(id)initWithCoder:(NSCoder *)coder { if (self = [super init]) { self.username = [coder decodeObjectForKey:@"username"]; self.password = [coder decodeObjectForKey:@"password"]; } return self; } -(void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.username forKey:@"username"]; [coder encodeObject:self.username forKey:@"password"]; } @end Monday, March 19, 12
  • 50. Time to Code! Monday, March 19, 12
  • 52. Cocoa Touch Foundation Framework • Core framework for non-UI functionality • Operating System Classes • threading, archiving, filesystem • Collections • Common collection types: arrays, dictionaries, sets • Networking support • XML Processing Monday, March 19, 12
  • 53. Cocoa Touch UIKit Framework • Framework for building iOS user interfaces • User Interface Elements • Tables, buttons, images, etc. • Views and View Controllers • Multitouch Event Handling • High-level Drawing Routines Monday, March 19, 12
  • 54. Understanding MVC Model,View, Controller Model View Controller Monday, March 19, 12
  • 55. UIView The “V” in MVC • Base class for iOS user interface components • Drawing and animation • Layout and subview management • Multitouch event handling • Xcode’s Interface Builder used to build UI • Archived version of UI stored in XIB/NIB file • Dynamically loaded at runtime by controller • Can be created programmatically Monday, March 19, 12
  • 56. UIViewController The “C” in MVC • The heart of every iOS app • Provides the “glue code” between the model and view • Responsible for managing the view hierarchy and lifecycle • Key view lifecycle methods: - (void)loadView; - (void)viewDidLoad; - (void)viewDidUnload; Monday, March 19, 12
  • 57. UIViewController: View Loading controller.view View Controller Is view nil? View loadView viewDidLoad 1) Overridden 2) Loaded from NIB 3) Return empty UIView Monday, March 19, 12
  • 58. View Unloading Dealing with low memory conditions • didReceiveMemoryWarning • Called by OS when low memory encountered • If possible, will release controller’s view • Can override, but must call super • viewDidUnload invoked if root view released • Override to release anything that can be recreated in loadView/viewDidLoad Monday, March 19, 12
  • 59. Display-related Callbacks viewWillAppear • Called immediately prior to being presented viewDidAppear • Called upon view being added to window viewWillDisappear • Called immediately before view is removed from window or is covered by another view viewDidDisappear • Called after view is removed from window or is covered by another view Monday, March 19, 12
  • 60. Outlets and Actions Wiring the View and View Controller • Provides metadata to Interface Builder to allow connections between objects • IBOutlet • Property reference to XIB/NIB objects • Null-defined C macro • IBAction • Used by Interface Builder to determine available actions • Void-defined C macro Monday, March 19, 12
  • 61. Time to Code! Monday, March 19, 12