SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
CS193p
                            Spring 2010




Wednesday, March 31, 2010
Enrollment Closed
                     You should have received an e-mail
                     It will confirm your grading status (P/NC or not)
                     As usual, we were oversubscribed for grading option
                     Sorry to anyone who didn’t get the option they wanted
                     If you received e-mail, but are not in Axess, do it!


                     ... and an invitation to iPhone Developer Program

                     If not, e-mail cs193p@cs.stanford.edu.




Wednesday, March 31, 2010
Communication

                            E-mail
                            Questions are best sent to cs193p@cs.stanford.edu
                            Sending directly to instructor or TA’s risks slow response.


                            Web Site
                            Very Important!
                            http://cs193p.stanford.edu
                            All lectures, assignments, code, etc. will be there.
                            This site will be your best friend when it comes to getting info.




Wednesday, March 31, 2010
Office Hours
                            Andreas
                            Monday 6pm to 8pm
                            Thursday 6pm to 8pm
                            Gates B26A
                            Bring your Stanford ID card for access to the building


                            Sonali
                            Friday 11am to 1pm
                            Thursday 1pm to 3pm
                            Gates B26B




Wednesday, March 31, 2010
Today’s Topics
                            MVC
                            Calculator


                            Objective-C
                            Declaring and implementing objects
                            Sending messages between objects


                            Interface Builder
                            “Wiring up” objects to send messages to each other
                            Setting up the properties of objects


                            Xcode
                            Managing all your code
                            Running your application in the simulator




Wednesday, March 31, 2010
Our Calculator
                               CalculatorViewController

                                     Controller

                                                          UILabel



                            Model                         View
                                               UIButton              UIButton
                 CalculatorBrain                    UIButton  UIButton
                                               UIButton    UIButton UIButton



Wednesday, March 31, 2010
Header File (public API)


                                                       Model

          @interface




          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model

          @interface CalculatorBrain




          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject




          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }




          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                            Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }
                                 Specifying void as the return type means
                                    that this method returns no value.
          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }
                     The name of this method is “setOperand:”

          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                                Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }
                                          It takes one argument, a double called “anOperand”

          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                 Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }
                                                       Don’t forget a semicolon here!

          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Header File (public API)


                                                               Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

                               This method returns a double.


          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                                 Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

                                               It takes a pointer to an NSString object as its argument.
                                                  That’s right, we’re passing an object to this method.
          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

          - (NSArray *)foo:(int)zap bar:(id)pow;

          @end


Wednesday, March 31, 2010
Header File (public API)


                                                                                 Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

          - (NSArray *)foo:(int)zap bar:(id)pow;

          @end                   This method takes two arguments and is called “foo:bar:”



Wednesday, March 31, 2010
Header File (public API)


                                                                      Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

          - (NSArray *)foo:(int)zap bar:(id)pow;

                               It returns a pointer to an NSArray
          @end
                                (a collection class in Foundation).


Wednesday, March 31, 2010
Header File (public API)


                                                                                   Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

          - (NSArray *)foo:(int)zap bar:(id)pow;

          @end                                               The second argument is of type “id”
                                                       This means “a pointer to *ANY* kind of object!”


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;

          - (NSArray *)foo:(int)zap bar:(id)pow;

          @end


Wednesday, March 31, 2010
Header File (public API)


                                                       Model
          #import <Foundation/Foundation.h>

          @interface CalculatorBrain : NSObject
          {
                      double operand;
          }


          - (void)setOperand:(double)anOperand;

         - (double)performOperation:(NSString *)operation;



          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                   Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain




          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                   Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
                     <code goes here>
                     return aDouble;
         }
          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                      Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain          No semicolon this time!

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
                     <code goes here>
                     return aDouble;
         }
          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                   Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
             [operation sendMessage:argument];
             return aDouble;
         }
          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                   Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
             [operation sendMessage:argument];
             return aDouble;
         }           Square brackets mean “send a message.”
          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                                                  Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
             [operation sendMessage:argument];
             return aDouble;
         }
          @end                 This is the object to send the message to
                        (in this case, the NSString called “operation” that was
                             passed as an argument to performOperation:).

Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                   Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
             [operation sendMessage:argument];
             return aDouble;
         }                         This is the message to send.
          @end


Wednesday, March 31, 2010
Implementation File
                            (private and public)

                                                             Model
          #import “CalculatorBrain.h”

          @implementation CalculatorBrain

          - (void)setOperand:(double)anOperand
          {
                     <code goes here>
          }

         - (double)performOperation:(NSString *)operation
         {
             [operation sendMessage:argument];
             return aDouble;
         }                        And this is its one (in this case) argument.
          @end


Wednesday, March 31, 2010
Controller

      #import <UIKit/UIKit.h>

      @interface CalculatorViewController : UIViewController
      {
         CalculatorBrain * brain;
                IBOutlet UILabel * display;
      }


      - (IBAction)digitPressed:(UIButton *)sender;
      - (IBAction)operationPressed:(UIButton *)sender;

      @end

Wednesday, March 31, 2010
Controller
                                    Our Controller inherits from
                                     UIViewController. UIKit
      #import <UIKit/UIKit.h>         supports MVC primarily
                                        through this class.

      @interface CalculatorViewController : UIViewController
      {
         CalculatorBrain * brain;
                IBOutlet UILabel * display;
      }


      - (IBAction)digitPressed:(UIButton *)sender;
      - (IBAction)operationPressed:(UIButton *)sender;

      @end

Wednesday, March 31, 2010
Controller

      #import <UIKit/UIKit.h>

      @interface CalculatorViewController : UIViewController
      {
         CalculatorBrain * brain;        This is going to point to our
                                                 CalculatorBrain   Model
                IBOutlet UILabel * display;
      }


      - (IBAction)digitPressed:(UIButton *)sender;
      - (IBAction)operationPressed:(UIButton *)sender;

      @end

Wednesday, March 31, 2010
These hook up to our   View

            Controller

      #import <UIKit/UIKit.h>

      @interface CalculatorViewController : UIViewController
      {
         CalculatorBrain * brain;
                IBOutlet UILabel * display;
      }


      - (IBAction)digitPressed:(UIButton *)sender;
      - (IBAction)operationPressed:(UIButton *)sender;

      @end

Wednesday, March 31, 2010
View

            Controller

      #import <UIKit/UIKit.h>

      @interface CalculatorViewController : UIViewController
      {                            Model
         CalculatorBrain * brain;
                IBOutlet UILabel * display;
      }


      - (IBAction)digitPressed:(UIButton *)sender;
      - (IBAction)operationPressed:(UIButton *)sender;

      @end

Wednesday, March 31, 2010
CalculatorViewController.xib


Wednesday, March 31, 2010
“File’s Owner” is our
                    Controller

   CalculatorViewController.xib


Wednesday, March 31, 2010
Wednesday, March 31, 2010
Wednesday, March 31, 2010
Wednesday, March 31, 2010
Xcode



                 A picture (or demo) is worth 1,000 words.




Wednesday, March 31, 2010

Más contenido relacionado

Destacado

Destacado (7)

Lecture 06
Lecture 06Lecture 06
Lecture 06
 
Lecture 03
Lecture 03Lecture 03
Lecture 03
 
Lecture 04
Lecture 04Lecture 04
Lecture 04
 
String slide
String slideString slide
String slide
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 

Similar a Lecture 2#- (Intro to Obj-C, Interface Builder and Xcode)

Model-Driven Software Development - Introduction & Overview
Model-Driven Software Development - Introduction & OverviewModel-Driven Software Development - Introduction & Overview
Model-Driven Software Development - Introduction & OverviewEelco Visser
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCMadusha Perera
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010Eliot Horowitz
 
Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Robert Lemke
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniquesjoaopmaia
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in SwiftYusuke Kita
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Altece
 
Data Loading for Ext GWT
Data Loading for Ext GWTData Loading for Ext GWT
Data Loading for Ext GWTSencha
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Codemotion
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupBrian Cardiff
 
Python programming lanuguage
Python programming lanuguagePython programming lanuguage
Python programming lanuguageBurhan Ahmed
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and AndroidHeiko Behrens
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 

Similar a Lecture 2#- (Intro to Obj-C, Interface Builder and Xcode) (20)

Model-Driven Software Development - Introduction & Overview
Model-Driven Software Development - Introduction & OverviewModel-Driven Software Development - Introduction & Overview
Model-Driven Software Development - Introduction & Overview
 
Ios fundamentals with ObjectiveC
Ios fundamentals with ObjectiveCIos fundamentals with ObjectiveC
Ios fundamentals with ObjectiveC
 
Reversing Google Protobuf protocol
Reversing Google Protobuf protocolReversing Google Protobuf protocol
Reversing Google Protobuf protocol
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)Creating Clean Code with AOP (T3CON10)
Creating Clean Code with AOP (T3CON10)
 
Using SQLite
Using SQLiteUsing SQLite
Using SQLite
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in Swift
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Data Loading for Ext GWT
Data Loading for Ext GWTData Loading for Ext GWT
Data Loading for Ext GWT
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetup
 
Python programming lanuguage
Python programming lanuguagePython programming lanuguage
Python programming lanuguage
 
Android Architecture components
Android Architecture componentsAndroid Architecture components
Android Architecture components
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and Android
 
Hems
HemsHems
Hems
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 

Último

Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Último (20)

Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 

Lecture 2#- (Intro to Obj-C, Interface Builder and Xcode)

  • 1. CS193p Spring 2010 Wednesday, March 31, 2010
  • 2. Enrollment Closed You should have received an e-mail It will confirm your grading status (P/NC or not) As usual, we were oversubscribed for grading option Sorry to anyone who didn’t get the option they wanted If you received e-mail, but are not in Axess, do it! ... and an invitation to iPhone Developer Program If not, e-mail cs193p@cs.stanford.edu. Wednesday, March 31, 2010
  • 3. Communication E-mail Questions are best sent to cs193p@cs.stanford.edu Sending directly to instructor or TA’s risks slow response. Web Site Very Important! http://cs193p.stanford.edu All lectures, assignments, code, etc. will be there. This site will be your best friend when it comes to getting info. Wednesday, March 31, 2010
  • 4. Office Hours Andreas Monday 6pm to 8pm Thursday 6pm to 8pm Gates B26A Bring your Stanford ID card for access to the building Sonali Friday 11am to 1pm Thursday 1pm to 3pm Gates B26B Wednesday, March 31, 2010
  • 5. Today’s Topics MVC Calculator Objective-C Declaring and implementing objects Sending messages between objects Interface Builder “Wiring up” objects to send messages to each other Setting up the properties of objects Xcode Managing all your code Running your application in the simulator Wednesday, March 31, 2010
  • 6. Our Calculator CalculatorViewController Controller UILabel Model View UIButton UIButton CalculatorBrain UIButton UIButton UIButton UIButton UIButton Wednesday, March 31, 2010
  • 7. Header File (public API) Model @interface @end Wednesday, March 31, 2010
  • 8. Header File (public API) Model @interface CalculatorBrain @end Wednesday, March 31, 2010
  • 9. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject @end Wednesday, March 31, 2010
  • 10. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } @end Wednesday, March 31, 2010
  • 11. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 12. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } Specifying void as the return type means that this method returns no value. - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 13. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } The name of this method is “setOperand:” - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 14. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } It takes one argument, a double called “anOperand” - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 15. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } Don’t forget a semicolon here! - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 16. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; This method returns a double. @end Wednesday, March 31, 2010
  • 17. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; It takes a pointer to an NSString object as its argument. That’s right, we’re passing an object to this method. @end Wednesday, March 31, 2010
  • 18. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; - (NSArray *)foo:(int)zap bar:(id)pow; @end Wednesday, March 31, 2010
  • 19. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; - (NSArray *)foo:(int)zap bar:(id)pow; @end This method takes two arguments and is called “foo:bar:” Wednesday, March 31, 2010
  • 20. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; - (NSArray *)foo:(int)zap bar:(id)pow; It returns a pointer to an NSArray @end (a collection class in Foundation). Wednesday, March 31, 2010
  • 21. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; - (NSArray *)foo:(int)zap bar:(id)pow; @end The second argument is of type “id” This means “a pointer to *ANY* kind of object!” Wednesday, March 31, 2010
  • 22. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; - (NSArray *)foo:(int)zap bar:(id)pow; @end Wednesday, March 31, 2010
  • 23. Header File (public API) Model #import <Foundation/Foundation.h> @interface CalculatorBrain : NSObject { double operand; } - (void)setOperand:(double)anOperand; - (double)performOperation:(NSString *)operation; @end Wednesday, March 31, 2010
  • 24. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain @end Wednesday, March 31, 2010
  • 25. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { <code goes here> return aDouble; } @end Wednesday, March 31, 2010
  • 26. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain No semicolon this time! - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { <code goes here> return aDouble; } @end Wednesday, March 31, 2010
  • 27. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { [operation sendMessage:argument]; return aDouble; } @end Wednesday, March 31, 2010
  • 28. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { [operation sendMessage:argument]; return aDouble; } Square brackets mean “send a message.” @end Wednesday, March 31, 2010
  • 29. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { [operation sendMessage:argument]; return aDouble; } @end This is the object to send the message to (in this case, the NSString called “operation” that was passed as an argument to performOperation:). Wednesday, March 31, 2010
  • 30. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { [operation sendMessage:argument]; return aDouble; } This is the message to send. @end Wednesday, March 31, 2010
  • 31. Implementation File (private and public) Model #import “CalculatorBrain.h” @implementation CalculatorBrain - (void)setOperand:(double)anOperand { <code goes here> } - (double)performOperation:(NSString *)operation { [operation sendMessage:argument]; return aDouble; } And this is its one (in this case) argument. @end Wednesday, March 31, 2010
  • 32. Controller #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController { CalculatorBrain * brain; IBOutlet UILabel * display; } - (IBAction)digitPressed:(UIButton *)sender; - (IBAction)operationPressed:(UIButton *)sender; @end Wednesday, March 31, 2010
  • 33. Controller Our Controller inherits from UIViewController. UIKit #import <UIKit/UIKit.h> supports MVC primarily through this class. @interface CalculatorViewController : UIViewController { CalculatorBrain * brain; IBOutlet UILabel * display; } - (IBAction)digitPressed:(UIButton *)sender; - (IBAction)operationPressed:(UIButton *)sender; @end Wednesday, March 31, 2010
  • 34. Controller #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController { CalculatorBrain * brain; This is going to point to our CalculatorBrain Model IBOutlet UILabel * display; } - (IBAction)digitPressed:(UIButton *)sender; - (IBAction)operationPressed:(UIButton *)sender; @end Wednesday, March 31, 2010
  • 35. These hook up to our View Controller #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController { CalculatorBrain * brain; IBOutlet UILabel * display; } - (IBAction)digitPressed:(UIButton *)sender; - (IBAction)operationPressed:(UIButton *)sender; @end Wednesday, March 31, 2010
  • 36. View Controller #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController { Model CalculatorBrain * brain; IBOutlet UILabel * display; } - (IBAction)digitPressed:(UIButton *)sender; - (IBAction)operationPressed:(UIButton *)sender; @end Wednesday, March 31, 2010
  • 38. “File’s Owner” is our Controller CalculatorViewController.xib Wednesday, March 31, 2010
  • 42. Xcode A picture (or demo) is worth 1,000 words. Wednesday, March 31, 2010