bootstrapping iphone development

23
Bootstrapping iPhone Development Munjal Budhabhatti Senior Consultant Sep/24/2009 San Antonio

Upload: thoughtworks

Post on 01-Nov-2014

3.061 views

Category:

Technology


2 download

DESCRIPTION

iPhone, the next generation mobile platform has revolutionized the way one uses phones as it's a combination of a phone, an iPod and an internet device. The iPhone is a richer platform for application delivery due to an exponential growth and wide spread usage.The critical factor, for a successful mobile application is the end user experience: application usability, reliability, and performance which the iPhone delivers in style. There are thousands of applications created by hundreds of developers for the iPhone. This kind of innovation helps you start developing the next generation of innovative mobile applications now.Topics Covered * Current State of iPhone Development * Fast Track to Objective C * Fast Track to XCode and Interface Builder * Getting Productive using OR-Framework, Testing, SerializationMunjal Budhabhatti is a senior solution developer at ThoughtWorks. He possesses over 10 years of experience in designing large-scale enterprise applications and has implemented innovative solutions for some of the largest microfinance, insurance and financial organizations. He loves writing well-designed enterprise applications using Agile processes. His article on "Test-Driven Development and Continuous Integration for Mobile Applications" was recently published in the Microsoft Architecture Journal.

TRANSCRIPT

Page 1: Bootstrapping iPhone Development

Bootstrapping iPhone Development

Munjal Budhabhatti Senior Consultant

Sep/24/2009 San Antonio

Page 2: Bootstrapping iPhone Development

Agenda

!!Current state of iPhone Development

!!Fast track to Objective – C

!!Fast track to XCode and Interface Builder

!!Getting productive using OR-Framework, Testing,

Serialization

Page 3: Bootstrapping iPhone Development

Current state of iPhone Development

•! Requirements

–! Intel based Mac with OSX 10.5

–! iPhone SDK (Sign-up for iPhone Developer Program $99 for a year)

–! Do NOT need iPhone or iPod Touch (Work on iPhone Simulator)

•! Developer Resources

http://developer.apple.com/iphone

http://devforums.apple.com

http://cs193p.stanford.edu

Page 4: Bootstrapping iPhone Development

Fast track to Objective – C

•! Object oriented programming language to write Applications for iPhone and Mac OS

•! Powerful set of extensions to the standard ANSI C language

–! Object oriented

–! Dynamic (Adds Smalltalk-style or Ruby-style messaging)

•! You manage your memory – Probably a good thing in mobile devices

Page 5: Bootstrapping iPhone Development

Objective – C Syntax

•! Objective – C is a strict superset thin layer on top of ANSI C

•! Compile any ANSI C program with Objective – C compiler

•! Object syntax derived from Smalltalk

•! Non object oriented syntax identical to C

•! A bit clumsy syntax. Can get lost in the woods. Do NOT let the syntax

defeat you.

Page 6: Bootstrapping iPhone Development

Coding in Objective – C

•! Classes are developed using a header and an implementation.

•! Names and types of instance variables and method signature in

header file. Implement methods in implementation file

Interface

@interface classname : superclassname { //instance variables

} +classMethod1; +(returnType) classMethod2; -instanceMethod1; -(returnType) instanceMethod2;

@end

Implementation

@implementation classname + classMethod1 { } + (returnType) classMethod2 { } - instanceMethod1 { } - (returnType) instanceMethod2 { }

Page 7: Bootstrapping iPhone Development

Messages (Methods) in Objective – C

•! Java and C# implements Simula-style programming model: a method

is bound to section of code in a compiler

•! Objective – C is based on sending messages to object instances.

Message is simply a name, resolved at runtime by the receiving object.

•! fullName = [firstName stringByAppendingString: lastName]

•! No type-checking. If the object cannot respond to a message it simply

ignores it. No NULL checking!! Yay!!

Page 8: Bootstrapping iPhone Development

Static and Dynamic Typing Objective – C

•! Static typing using NSObject – the mother of almost all objects. You

can have objects that don’t derive from NSObject.

•! Dynamic typing using id

–! Sending messages to Nil is OK

–! Dynamic objection creation: objc_getClass, class_createInstance,

class_getInstanceMethod, class_getInstanceVariable

–! TypeIntrospection : isMemberOfClass & isKindOfClass

Page 9: Bootstrapping iPhone Development

Invocation and Memory Management in Objective – C

•! Memory management possible using Garbage collector for Mac OS

•! You manage your memory for iPhone OS

•! LeanManager *ronCampbell = [[LeanManager alloc] init];

Page 10: Bootstrapping iPhone Development

Protocols in Objective – C

•! Supports multiple-inheritance of specification

•! Similar to Interface in C# and Java. However, the methods could be

optional.

•! Used to declare methods that could be implemented by any class

•! Used to declare interface to an object while concealing its class

•! Used to capture similarities among classes that are not in hierarchy

Page 11: Bootstrapping iPhone Development

Protocol Example in Objective – C

@protocol Serialization - (void) serialize; - (void) deserialize;

@end

@interface AccountImage : Image <Serialization> - (void) serialize; - (void) deserialize;

@end

Page 12: Bootstrapping iPhone Development

Forwarding in Objective – C

•! Dynamic nature of Objective C allows forwarding of messages

•! If an object doesn’t respond to a message, it can forward to one that

probably could.

•! Similar to method_missing in Ruby

•! ages = [persons age]

Page 13: Bootstrapping iPhone Development

Category in Objective – C

•! A category allows you to add methods to an existing class – even for

ones that you don’t own or have the source code

•! Allows to extend the functionality without subclassing

•! Split the implementation of your class between several files

•! Caveat: Cannot create new instance variable in a class

Page 14: Bootstrapping iPhone Development

Fast track to Interface Builder

•! App for iPhone devs to create GUI

•! Typical MVC pattern. Write models and controllers in Xcode. Build

interface in Interface Builder

•! One could build interface using code. However, I would advise to bear

the pain once and learn using Interface Builder with Xcode.

•! Nib file and the magic

Page 15: Bootstrapping iPhone Development

Fast Track to OR-framework such as Active Record

•! Beautify your models

–! Will you make raw SQL calls ?

•! Start using ObjectPersistentFramework

Page 16: Bootstrapping iPhone Development

Fast track to Testing

•! Test using GoogleToolbox

•! Mock using OCMock

•! Serialization using JSON framework for iPhone

Page 17: Bootstrapping iPhone Development

iPhone development fundamentals

•! Cocoa Touch – Framework to develop touchscreen applications: UI

elements, event dispatching, application lifecycle

•! Media – Graphics, animations, sound, video

•! Core Services – Collections, Strings, Location, SQLLite, Networking

•! Core OS Layer – Standard IO/, Power Management

Page 18: Bootstrapping iPhone Development

main() method

•! Java/C# developers look for “main()” method

•! NSApplication provides the central framwork for app execution

•! Every app creates one instance of NSApplication in main()

•! After NSApplication creation, load the Nib file and start event loop

•! Nib file loads the UI

•! applicationDidFinishLauching() method called when app is launched

Page 19: Bootstrapping iPhone Development

View Controllers

•! Model View Controller Pattern

•! Each view in an iPhone app is managed by UIViewController

•! Mother of all view classes

•! Importance of IBAction and IBOutlet

•! IBAction: editButtonClicked()

•! IBOutlet: UILabel

Page 20: Bootstrapping iPhone Development

Table View Controller

•! Define and populate NSMutableArray in initWithCoder

•! Implement numberOfRowsInSection protocol for tabelView

•! Implement cellForRowAtIndexPath

•! Improve performance by reusing cells

Page 21: Bootstrapping iPhone Development

Navigation Controller

•! Mail app is the best way to understand navigation controller

•! Navigation controller maintains stack of view controllers

•! Each controller represents one node in hierarchy

•! Typical push and pop to manage controllers

•! [self.navigationController pushViewController: self.ctr animate:YES]

•! [self.navigationController popViewControllerAnimate: YES];

Page 22: Bootstrapping iPhone Development

File I/O

•! Your appliction is Sandboxed. Cannot access data from other apps

•! Documents directory

•! Tmp directory

Page 23: Bootstrapping iPhone Development