iOS Standford course

Embed Size (px)

Citation preview

  • 7/30/2019 iOS Standford course

    1/63

    Stanford CS193pDeveloping Applications for iOS

    Fall 2011

  • 7/30/2019 iOS Standford course

    2/63

    TodayWhat is this class all about?Description

    PrerequisitesHomework / Final Project

    iOS OverviewWhats in iOS?

    MVCObject-Oriented Design Concept

    Objective CNew language!Basic concepts only for today.

  • 7/30/2019 iOS Standford course

    3/63

    What will I learn in this courHow to build cool appsEasy to build even very complex applications

    Result 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 model

    Many computer science concepts applied in a commercial development platform:Databases, Graphics, Multimedia, Multithreading, Animation, Networking, and muNumerous students have gone on to sell products on the AppStore

  • 7/30/2019 iOS Standford course

    4/63

    PrerequisitesMost Important Prereq!Object-Oriented Programming

    CS106A&B required, CS107 recommended

    Object-Oriented TermsClass (description/template for an object)Instance (manifestation of a class)Message (sent to object to make it act)Method (code invoked by a Message)

    Instance Variable (object-specific storage)Superclass/Subclass (Inheritance)Protocol (non-class-specific methods)

    You should know thIf you are not very comforta

    these, this might not be the

    Programming ExperThis is an upper-level CS cou

    If you have never written a had to design and implementhandful of classes, this will

    difficulty for you.

  • 7/30/2019 iOS Standford course

    5/63

    AssignmentsWeekly Homework7 weekly assignments

    Assigned Thursday after lectureDue the following Wednesday at 11:59pmIndividual work onlyHomework graded , + and - based on

    Required Tasks and Evaluation criteriaLots of extra credit available, bank itOnly 3 free late days per quarter

    #1 fail: falling behind on homework

    Final Project3 weeks to work on it

    But weighted like 4 weeks Proposal requires instructoSome teams of 2 might be Keynote presentation requir

  • 7/30/2019 iOS Standford course

    6/63

    Core OSOSX Kernel

    Mach 3.0

    BSD

    Sockets

    Security

    Power Manage

    Keychain Acce

    Certificates

    File System

    Bonjour

    iOS

    Cocoa Touch

    Media

    Core Services

    Core OS

  • 7/30/2019 iOS Standford course

    7/63

    Core ServicesCollections

    Address Book

    Networking

    File Access

    SQLite

    Core Locatio

    Net Services

    Threading

    Preferences

    URL Utilities

    iOS

    Cocoa Touch

    Media

    Core Services

    Core OS

  • 7/30/2019 iOS Standford course

    8/63

    MediaCore Audio

    OpenAL

    Audio Mixing

    Audio Recording

    Video Playback

    JPEG, PNG

    PDF

    Quartz (2

    Core Anim

    OpenGL E

    iOS

    Cocoa Touch

    Media

    Core Services

    Core OS

  • 7/30/2019 iOS Standford course

    9/63

    Cocoa TouchMulti-Touch

    Core Motion

    View Hierarchy

    Localization

    Controls

    Alerts

    Web View

    Map Kit

    Image Pic

    Camera

    iOS

    Cocoa Touch

    Media

    Core Services

    Core OS

  • 7/30/2019 iOS Standford course

    10/63

    Platform Components

    Tools

    Language

    Frameworks

    Design Strategies

    [display setTextColor:[UIColor blackColor]]

    Foundation UIKit

    MVC

    CoreData

    MapKit

    Xcode 4 Instrumen

    ts

    CoreM

    http://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.apphttp://localhost/Developer/Applications/Instruments.app
  • 7/30/2019 iOS Standford course

    11/63

    Controller

    MVC

    Model View

    Divide objects in your program into 3 camps.

  • 7/30/2019 iOS Standford course

    12/63

    Controller

    MVC

    Model View

    Model = What your application is (but not how it is d

  • 7/30/2019 iOS Standford course

    13/63

    Controller

    MVC

    Model View

    Controller = How your Model is presented to the user

  • 7/30/2019 iOS Standford course

    14/63

    Controller

    MVC

    Model View

    View = Your Controllers minions

  • 7/30/2019 iOS Standford course

    15/63

    Controller

    MVC

    Model View

    Its all about managing communication between c

  • 7/30/2019 iOS Standford course

    16/63

    Controller

    MVC

    Model View

    Controllers can always talk directly to their Mo

  • 7/30/2019 iOS Standford course

    17/63

    Controller

    MVC

    Model View

    outlet

    Controllers can also talk directly to their View

  • 7/30/2019 iOS Standford course

    18/63

    Controller

    MVC

    Model View

    outlet

    The Model and View should never speak to each o

  • 7/30/2019 iOS Standford course

    19/63

    Controller

    MVC

    Model View

    ?outlet

    Can the View speak to its Controller?

  • 7/30/2019 iOS Standford course

    20/63

    Controller

    MVC

    Model View

    outlet

    Sort of. Communication is blind and structure

  • 7/30/2019 iOS Standford course

    21/63

    Controller

    MVC

    Model View

    outlet

    target

    The Controller can drop a target on itself.

  • 7/30/2019 iOS Standford course

    22/63

    Controller

    MVC

    Model View

    act

    outlet

    target

    Then hand out an action to the View.

  • 7/30/2019 iOS Standford course

    23/63

    Controller

    MVC

    Model View

    act

    outlet

    target

    The View sends the action when things happen in t

  • 7/30/2019 iOS Standford course

    24/63

    Controller

    MVC

    Model View

    act

    outlet

    should

    will did

    target

    Sometimes the View needs to synchronize with the C

  • 7/30/2019 iOS Standford course

    25/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    should

    will did

    target

    The Controller sets itself as the Views delegat

  • 7/30/2019 iOS Standford course

    26/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    should

    will did

    target

    The delegate is set via a protocol (i.e. its blind to

  • 7/30/2019 iOS Standford course

    27/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    should

    will did

    target

    Views do not own the data they display.

  • 7/30/2019 iOS Standford course

    28/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    should

    will did

    target

    countdataat

    So, if needed, they have a protocol to acquire

  • 7/30/2019 iOS Standford course

    29/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    Controllers are almost always that data source (not

    MVC

  • 7/30/2019 iOS Standford course

    30/63

    Controllers interpret/format Model information for t

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    MVC

  • 7/30/2019 iOS Standford course

    31/63

    Controller

    MVC

    Model View

    act

    ? delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    Can the Model talk directly to the Controller

    MVC

  • 7/30/2019 iOS Standford course

    32/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    No. The Model is (should be) UI independent

    MVC

  • 7/30/2019 iOS Standford course

    33/63

    Controller

    MVC

    Model View

    act

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    So what if the Model has information to update or so

    MVC

  • 7/30/2019 iOS Standford course

    34/63

    Controller

    MVC

    Model View

    act

    Notification& KVO

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    It uses a radio station-like broadcast mechani

    MVC

  • 7/30/2019 iOS Standford course

    35/63

    Controller

    MVC

    Model View

    act

    Notification& KVO

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    Controllers (or other Model) tune in to interesting

    MVC

  • 7/30/2019 iOS Standford course

    36/63

    A View might tune in, but probably not to a Models

    Controller

    MVC

    Model View

    act

    Notification& KVO

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    MVC

  • 7/30/2019 iOS Standford course

    37/63

    Controller

    MVC

    Model View

    act

    Notification& KVO

    delegate

    outlet

    data

    source

    should

    will did

    target

    countdataat

    Now combine MVC groups to make complicated prog

    MVCs working together

  • 7/30/2019 iOS Standford course

    38/63

    MVCs working together

    MVCs not working togethe

  • 7/30/2019 iOS Standford course

    39/63

    MVCs not working togethe

    Objective C

  • 7/30/2019 iOS Standford course

    40/63

    Objective-CNew language to learn!Strict superset of CAdds syntax for classes, methods, etc.A few things to think differently about (e.g. properties, dynamic binding)

    Most important concept to understand today: PropertiUsually we do not access instance variables directly in Objective-C.Instead, we use properties.A property is just the combination of a getter method and a setter method in aThe getter has the name of the property (e.g. myValue)

    The setters name is set plus capitalized property name (e.g. setMyValue:)(To make this look nice, we always use a lowercase letter as the first letter of a We just call the setter to store the value we want and the getter to get it. Sim

    This is just your first glimpse of this language!Well go much more into the details next week.Dont get too freaked out by the syntax at this point.

    Objective C

  • 7/30/2019 iOS Standford course

    41/63

    Objective-CSpaceship.h

    Objective C

  • 7/30/2019 iOS Standford course

    42/63

    Objective-CSpaceship.h

    Objective C

  • 7/30/2019 iOS Standford course

    43/63

    Objective-CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    44/63

    Objective-CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    45/63

    Objective-CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    46/63

    Objective-CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    47/63

    Objective-CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    48/63

    Objective CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    49/63

    Objective CSpaceship.h

    Objective-C

  • 7/30/2019 iOS Standford course

    50/63

    Objective CSpaceship.h

    Objective-CS hi h

  • 7/30/2019 iOS Standford course

    51/63

    Objective CSpaceship.h

    Objective-CS hi h

  • 7/30/2019 iOS Standford course

    52/63

    Objective CSpaceship.h

    Objective-CS hi h

  • 7/30/2019 iOS Standford course

    53/63

    Objective CSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    54/63

    O jec ive CSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    55/63

    jSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    56/63

    jSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    57/63

    jSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    58/63

    jSpaceship.h

    Objective-CSpaceship h

  • 7/30/2019 iOS Standford course

    59/63

    jSpaceship.h

    Objective-CSpaceship.h

  • 7/30/2019 iOS Standford course

    60/63

    Spaceship.h

    Objective-CSpaceship.h

  • 7/30/2019 iOS Standford course

    61/63

    Spaceship.h

    Objective-CSpaceship.h

  • 7/30/2019 iOS Standford course

    62/63

    Spaceship.h

    Coming Up

  • 7/30/2019 iOS Standford course

    63/63

    g pNext LectureOverview of the Integrated Development Environment (IDE, i.e. Xcode 4)Objective-C in action

    Concrete example of MVCMajor demonstration of all of the above: RPN Calculator

    (HOMEWORK: if you do not know what an RPN Calculator is, look it up on the i

    FridayVery simple introduction to using the debugger.Optional. You can figure it out on your own if you want (not too difficult).

    Next WeekObjective-C language in depthFoundation classes: arrays, dictionaries, strings, etc.Dynamic vs. static typingProtocols, categories and much, much more!