lecture 1

42
Stanford CS193p Developing Applications for iOS Fall 2010 Stanford CS193p Fall 2010

Upload: r-ben-as

Post on 22-Nov-2014

202 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 1

Stanford CS193pDeveloping Applications for iOS

Fall 2010

StanfordCS193p

Fall 2010

Page 2: Lecture 1

TodayLogisticsLecturesCommunicationHomework / Final ProjectRequirements

iOS Overview

MVCObject-Oriented Design Concept

StanfordCS193p

Fall 2010

Page 3: Lecture 1

LogisticsLecturesTell you (Tuesday)Show you (Thursday)Let you do it yourself (Homework)

Friday TA SectionPractical matters (e.g. debugging)KPCB EntrepreneurshipSpecial topics (guest lecturers)

Communicationhttp://cs193p.stanford.eduLectures, demo code and homeworkClass announcements

Homework7 weekly assignmentsAssigned Thursday after lectureDue the following Wednesday at 11:59pmIndividual work only

Final Project3 weeks to work on itProposal requires instructor approvalSome teams of 2 might be allowedKeynote presentation required (3 mins or so)

StanfordCS193p

Fall 2010

Page 4: Lecture 1

RequirementsMust have a MacIntel-basedSnow Leopard

HardwareNot required for homeworkRequired for final project (iOS4 or iPad) iPod Touch loaners available

TextbookApple on-line documentationhttp://developer.apple.com

PrerequisitesObject-Oriented ProgrammingCS106A&B required, CS107 recommended

Object-Oriented TermsClass (description/template for an object)Instance (manifestation of a class)Message (sent to objects to make them act)Method (code invoked by a Message)Instance Variable (object-specific storage)Inheritance (code-sharing mechanism)Superclass/Subclass (Inheritance relationships)Protocol (non-class-specific method declaration)

You should know these!If you are not very comfortable with all of these, this might not be the class for you

StanfordCS193p

Fall 2010

Page 5: Lecture 1

iOS4 SDKRequired for all homework assignments and final projectIt’s free!Download Xcode/SDK from iOS Dev Center at http://developer.apple.comTo run on a device (not just in simulator), you must join a ProgramiOS Developer University Program = free for Stanford students = Device YES, AppStore NONormal Developer Program = $99/year = Device YES, AppStore YES

iOS Developer University ProgramEnrolled students will receive an invitation to their Stanford e-mail accountsFollow the directions to join the Program and download the Xcode/SDK (if you haven’t already)Submit your UDID to the staff via e-mailValid through the end of the quarter only

StanfordCS193p

Fall 2010

Page 6: Lecture 1

What will I learn in this course?How to build cool appsEasy to build even very complex applicationsResult lives in your pocket!Very easy to distribute your application through the AppStoreVibrant development community

Real-life Object-Oriented ProgrammingThe heart of Cocoa Touch is 100% object-orientedApplication of MVC design modelMany computer science concepts applied in a commercial development platform: Databases, Graphics, Multimedia, Multithreading, Animation, Networking, and much, much more!Numerous students have gone on to sell products on the AppStore

StanfordCS193p

Fall 2010

Page 7: Lecture 1

Core OSOSX Kernel

Mach 3.0

BSD

Sockets

Security

Power Management

Keychain Access

Certificates

File System

Bonjour

iOSCocoa Touch

Media

Core Services

Core OS

StanfordCS193p

Fall 2010

Page 8: Lecture 1

Core ServicesCollections

Address Book

Networking

File Access

SQLite

Core Location

Net Services

Threading

Preferences

URL Utilities

iOSCocoa Touch

Media

Core Services

Core OS

StanfordCS193p

Fall 2010

Page 9: Lecture 1

MediaCore Audio

OpenAL

Audio Mixing

Audio Recording

Video Playback

JPEG, PNG, TIFF

PDF

Quartz (2D)

Core Animation

OpenGL ES

iOSCocoa Touch

Media

Core Services

Core OS

StanfordCS193p

Fall 2010

Page 10: Lecture 1

Cocoa TouchMulti-Touch

Core Motion

View Hierarchy

Localization

Controls

Alerts

Web View

Map Kit

Image Picker

Camera

iOSCocoa Touch

Media

Core Services

Core OS

StanfordCS193p

Fall 2010

Page 11: Lecture 1

Platform Components

Tools

Language

Frameworks

Design Strategies

[display setTextColor:[UIColor blackColor]];

Foundation UIKit

MVCCor

e Data

Map Kit

Xcode

Interface Builder

Instruments

Core Motion

StanfordCS193p

Fall 2010

Page 12: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

Page 13: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

Divide objects in your program into 3 “camps.”

Page 14: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

Model = What your application is (but not how it is displayed)

Page 15: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

Controller = How your Model is presented to the user (UI logic)

Page 16: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

View = Your Controller’s minions

Page 17: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

It’s all about managing communication between camps

Page 18: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

Controllers can always talk directly to their Model.

Page 19: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

outlet

Controllers can also talk directly to their View.

Page 20: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

outlet

The Model and View should never speak to each other.

Page 21: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

?outlet

Can the View speak to its Controller?

Page 22: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

outlet

Sort of. Communication is “blind” and structured.

Page 23: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

outlet

target

The Controller can drop a target on itself.

Page 24: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

outlet

target

Then hand out an action to the View.

Page 25: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

outlet

target

The View sends the action when things happen in the UI.

Page 26: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

outlet

should

will did

target

Sometimes the View needs to synchronize with the Controller.

Page 27: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

should

will did

target

The Controller sets itself as the View’s delegate.

Page 28: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

should

will did

target

The delegate is set via a protocol (i.e. it’s “blind” to class).

Page 29: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

should

will did

target

Views do not own the data they display.

Page 30: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

should

will did

target

countdataat

So, if needed, they have a protocol to acquire it.

Page 31: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

data source

should

will did

target

countdataat

Controllers are almost always that data source (not Model!).

Page 32: Lecture 1

Controllers interpret/format Model information for the View. StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

data source

should

will did

target

countdataat

Page 33: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

? delegate

outlet

data source

should

will did

target

countdataat

Can the Model talk directly to the Controller?

Page 34: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

data source

should

will did

target

countdataat

No. The Model is (should be) UI independent.

Page 35: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

delegate

outlet

data source

should

will did

target

countdataat

So what if the Model has information to update or something?

Page 36: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

Notification& KVO

delegate

outlet

data source

should

will did

target

countdataat

It uses a “radio station”-like broadcast mechanism.

Page 37: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

Notification& KVO

delegate

outlet

data source

should

will did

target

countdataat

Controllers (or other Model) “tune in” to interesting stuff.

Page 38: Lecture 1

A View might “tune in,” but probably not to a Model’s “station.”StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

Notification& KVO

delegate

outlet

data source

should

will did

target

countdataat

Page 39: Lecture 1

StanfordCS193p

Fall 2010

Controller

MVC

Model View

action

Notification& KVO

delegate

outlet

data source

should

will did

target

countdataat

Now combine MVC groups to make complicated programs ...

Page 40: Lecture 1

MVCs working together

StanfordCS193p

Fall 2010

Page 41: Lecture 1

MVCs not working together

StanfordCS193p

Fall 2010

Page 42: Lecture 1

Coming UpNext LectureOverview of the Development EnvironmentXcodeObjective-C introInterface BuilderConcrete example of MVCMajor demonstration of all of the above: Calculator

Friday (optional)Installing the SDK and using the debugger (this is the only time that will be covered)

Next WeekObjective-C language in depth Foundation classes: arrays, dictionaries, strings, etc.Dynamic and static typingMemory Management Stanford

CS193pFall 2010