iPhone Programming in 30 minutes (?) [FTS]

Preview:

DESCRIPTION

Talk at PhD Computer Science students’ Journal Club in Cardiff University (FTS - Food, Talks and Stuff).

Citation preview

iPhone Programming in ~30 mins (?)

Diego Pizzocaro

27.01.2010FTS seminar

These slides are heavily based on Evan Doll and Alan Cannistraro’s slides prepared for iPhone App Programming course @ Stanford

http://www.stanford.edu/class/cs193p

Look for iPhone Application Programming in iTunes U for videopodcasts.

Disclaimer

Crash course

• iPhone OS overview

• Objective-C

• Model-View-Controller (MVC)

iPhone OS overview

iPhone

Mac OS X

Cocoa

Media

Core Services

Core OS

iPhone

Cocoa Touch

Media

Core Services

Core OS

UI application framework

which as a developer you

are using the most

Cocoa Touch

Developing on iPhone

Xcode Interface Builder

Tools

Language (& Runtime)

Objective-C

[textView setStringValue: @“Hello”];

Frameworks

Foundation UIKit

Thursday, April 2, 2009

Xcode Interface Builder

Tools

Language (& Runtime)

Objective-C

[textView setStringValue: @“Hello”];

Frameworks

Foundation UIKit

Thursday, April 2, 2009

Tools

Xcode Interface Builder

Frameworks

Xcode Interface Builder

Tools

Language (& Runtime)

Objective-C

[textView setStringValue: @“Hello”];

Frameworks

Foundation UIKit

Thursday, April 2, 2009

Foundation UIKit

Language (& Runtime)

[textView setStringValue: @“Hello”];Objective-C

Objective-C

Objective-C• Strict superset of C

‣ Mix C with Obj-C

• Object oriented language

• Based on message passing (similar to Smalltalk)

• No garbage collector need to manually manage memory(not covered in this presentation)

Message Syntax

[receiver message];

[receiver message:argument];

[receiver message:arg1 andArg:arg2];

Message Examples

BankAccount *myAccount; //assume this exists

int n = [myAccount accountNumber];

[myAccount deposit:100];

if([myAccount isNotEmpty]) { [myAccount withdraw:50 printReceipt:YES];

}

Some new types

• Anonymous Objects

• Class

• ...others but no time!

(Selectors “SEL”, Boolean “BOOL”, etc.)

Anonymous Objects

• Normal (or Statically-typed) object

BankAccount *anAccount

• Anonymous (or Dynamically-typed) object

id anAccount

- Just id (Not id*)

- id is the data type that indicates that we are talking about an object

Class

• class instances responds to instance methods “-”- (id)init; - (double)accountNumber;

int n = [myAccount accountNumber];

• classes responds to class methods “+” (like Java “static” methods)

+ (id)alloc;

+ (float)stdInterestRate;

float rate = [BankAccount stdInterestRate];

Defining a classDefining a classA public header and a private implementation

Header File Implementation File

Defining a classA public header and a private implementation

Header File Implementation FileHeader File Implementation File

A public header and a private implementation

DemoDefining a classA public header and a private implementation

Header File Implementation File

Defining a classA public header and a private implementation

Header File Implementation FileBankAccount.h BankAccount.m

BankAccount class

Model - View - Controller (MVC)

Address Book

App Architecture

Model View

Controller

Xcode

Interface Builder

Model View

Controller

MVC• Only the Controller knows both Model and View

• Makes code more reusable (especially the Model part)

Demo

BankAccount

balance

- initWithBalance- setBalance- balance

BankAccount

balance

- initWithBalance- setBalance- balance

BankAccount

balance

- initWithBalance- setBalance- balance

ModelBankAccount app

ViewMainWindow.xib

AccountController

sliderlabelmyBankAccount

- updateAccount

Controller

Value Changed EVENT

Outlets

Action

Demo

BankAccount

balance

- initWithBalance- setBalance- balance

BankAccount

balance

- initWithBalance- setBalance- balance

BankAccount

balance

- initWithBalance- setBalance- balance

ModelBankAccount app

ViewMainWindow.xib

AccountController

sliderlabelmyBankAccount

- updateAccount

Controller

Value Changed EVENT

Your turn! ;)

Image from: http://www.trumpetvine.com/sketchblog/wp-content/images/2007.07/iphone_lg.jpg

• http://www.stanford.edu/class/cs193p

• http://cs193p.com/

• iTunes U - “iPhone Application Programming”

• iPhone Developer Program

(FREE, but cannot deploy on real iPhone)

• users.cs.cf.ac.uk/D.Pizzocaro