23
iPhone SDK App Development part 1: a very concise introduction

iPhone SDK dev sharing - the very basics

Embed Size (px)

DESCRIPTION

Prepared for a small team sharing session. It was meant to be a 20 mins sharing to fellow developers who have otherwise had no exposure or experience to Objective-C or GUI programming.

Citation preview

Page 1: iPhone SDK dev sharing - the very basics

iPhone SDK App Developmentpart 1: a very concise introduction

Page 2: iPhone SDK dev sharing - the very basics

iPhone SDK

the iPhone OS and iPhone SDK dates back to 15+ years ago - both originate from NeXTStep

consists of Xcode, Interface Builder, Instruments, iPhone Simulator and more...

free download!

developer.apple.com/iphone

Page 3: iPhone SDK dev sharing - the very basics

iPhone SDK Essential Facts

pre-requisites: Intel Mac, Mac OS X 10.5 Leopard, Obj C, OO programming concepts

patience, clean mindset

test on real devices & AppStore submission:

iPhone developer programme ($99 per year)

Page 4: iPhone SDK dev sharing - the very basics

The iPhone OS

cocoa touch: UIKit framework (iphone specific), Foundation framework (wrappers to Core Foundation String, network, data structures, i18n.etc.)

media layer: Quartz (2d vector based drawing api), Core Animation, OpenGL, Audio, Video codecs

core services layer: Address Book, Core Foundation, Core Location, Security, SQLite, XML

core OS layer: Threading, IO, Memory, File Access, Networking

Page 5: iPhone SDK dev sharing - the very basics

Objective-C: a quick look like C++/Java, but weirder

you don’t invoke object instances, you send messages to them indirectly

most of the OO and C++/Java concepts apply, like inheritance, polymorphism.etc.

some syntax difference to make you aware being in Obj-C or C space

java: calculator.sum(num1Value, num2Value, num3Value);

c++: calculator-> sum(num1Value, num2Value, num3Value);

obj-c: [calculator sum: num1Value withNum2:num2Value withNum3: num3Value]

Page 6: iPhone SDK dev sharing - the very basics

A typical Objective C class

#import <Foundation/Foundation.h>

@interface SomeClass:SomeParentClass{ BOOL someBooleanValue; @private int someNumber;

$protected NSString someString;}

+ (id) alloc;+ (BOOL) anotherClassMethod;- (BOOL) returnSomeBooleanValueMethod;- (NSString) getSomeStringMethod;- (void) setValueOfSomeString: (NSString)someString;

@end

Page 7: iPhone SDK dev sharing - the very basics

UIKit

Objective-C framework for event handling, drawing model, windows, views, and controls designed for iPhone

apps created in Xcode are linked to UIKit

runtime foundation for iPhone apps

Page 8: iPhone SDK dev sharing - the very basics

UIWindow: space on a screen, like a picture frame

only covers the basics todayUIKit elements

UIView: base class of all visual objects. like a canvas.

View Controller handles multiple views, orientation changes, transitions.etc.

Page 9: iPhone SDK dev sharing - the very basics

The First App

main.mHelloViewAppDelegate

<interface>

HelloViewAppDelegate<impl>

app that displays an empty view

Page 10: iPhone SDK dev sharing - the very basics

main.mmain.m created by Xcode

hooks up obj-c framework

creates auto-release pool

Page 11: iPhone SDK dev sharing - the very basics

main.mHelloViewAppDelegate

<interface>

HelloViewAppDelegate<impl>

Page 12: iPhone SDK dev sharing - the very basics

HelloViewAppDelegate<impl>

app delegate class: main helper class for handling important life-cycle events

often the bridge between your app and system frameworks, e.g. CoreLocation

Page 13: iPhone SDK dev sharing - the very basics

creates a UIView object with size of whole screen

add the view to main UIWindow object

make window visible

mark the objects for release upon exit

Page 14: iPhone SDK dev sharing - the very basics

demo

Page 15: iPhone SDK dev sharing - the very basics

Adding a bit of text

for convenience, create a MainView class extending from UIView, attach an UITextView object to it, then add it back to the main window object

main.mHelloViewAppDelegate

<interface>

HelloViewAppDelegate<impl>

MainView

Page 16: iPhone SDK dev sharing - the very basics

HelloWoldAppDelegate.h

Page 17: iPhone SDK dev sharing - the very basics

sets “Hello, World!” to its UITextView object

init a MainView object

attach it to the app delegate window object

Page 18: iPhone SDK dev sharing - the very basics

demo

Page 19: iPhone SDK dev sharing - the very basics

Adding orientation change support

create a ViewController class to do the heavy lifting

main.mControllerDemoAppDelegate

<interface>

ControllerDemoAppDelegate<impl>

ControlDemoViewController

Page 20: iPhone SDK dev sharing - the very basics

init custom ViewController object

Page 21: iPhone SDK dev sharing - the very basics

in this ViewController object, didRotateFromInterfaceOrientation() is overridden to change the text whenever the iPhone is rotated

Page 22: iPhone SDK dev sharing - the very basics

demo

Page 23: iPhone SDK dev sharing - the very basics

end of part i

next:

TabViewControllers, Interface Builder, Window Applications, Frameworks, AppStore submission and more