bootstrapping iphone development
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
Bootstrapping iPhone Development
Munjal Budhabhatti Senior Consultant
Sep/24/2009 San Antonio
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
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
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
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.
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 { }
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!!
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
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];
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
Protocol Example in Objective – C
@protocol Serialization - (void) serialize; - (void) deserialize;
@end
@interface AccountImage : Image <Serialization> - (void) serialize; - (void) deserialize;
@end
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]
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
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
Fast Track to OR-framework such as Active Record
•! Beautify your models
–! Will you make raw SQL calls ?
•! Start using ObjectPersistentFramework
Fast track to Testing
•! Test using GoogleToolbox
•! Mock using OCMock
•! Serialization using JSON framework for iPhone
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
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
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
Table View Controller
•! Define and populate NSMutableArray in initWithCoder
•! Implement numberOfRowsInSection protocol for tabelView
•! Implement cellForRowAtIndexPath
•! Improve performance by reusing cells
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];
File I/O
•! Your appliction is Sandboxed. Cannot access data from other apps
•! Documents directory
•! Tmp directory