Stanford Cs193P: Developing Applications For Iphone 4, Ipod Touch, & Ipad Fall 2010
Stanford Cs193P: Developing Applications For Iphone 4, Ipod Touch, & Ipad Fall 2010
Stanford
CS193p
Fall 2010
Today
MVC
Calculator
Objective-C
Declaring and implementing objects
Sending messages between objects
Interface Builder
Graphically creating your View
“Wiring up” objects to send messages to each other
Setting the properties of objects
Xcode
Managing and editing your code
Running your application in the simulator
Stanford
CS193p
Fall 2010
Calculator MVC
should target
will did
Controller
data
count
at
outlet
de
da
ta
le
g
so
at
e
u rc action
e
Model View
Stanford
CS193p
Fall 2010
Calculator MVC
target
Controller
outlet
action
Model View
Stanford
CS193p
Fall 2010
Calculator MVC
target
Controller
outlet
action
Model View
CalculatorBrain Stanford
CS193p
Fall 2010
Calculator MVC
CalculatorViewController
target
Controller
outlet
action
Model View
CalculatorBrain Stanford
CS193p
Fall 2010
Calculator MVC
CalculatorViewController
target
Controller
outlet
el
b
La
action
UI
3.21 1
7 X
Model 4 View -
+ 2
UIButtons
CalculatorBrain Stanford
CS193p
Fall 2010
Calculator MVC
CalculatorViewController
target
Controller
display
el
b
La
action
UI
3.21 1
7 X
Model 4 View -
+ 2
UIButtons
CalculatorBrain Stanford
CS193p
Fall 2010
Calculator MVC
CalculatorViewController
target
Controller
display
el
b
La
operationPressed:
UI
digitPressed:
3.21 1
7 X
Model 4 View -
+ 2
UIButtons
CalculatorBrain Stanford
CS193p
Fall 2010
CalculatorBrain.h This is the header file for this class.
It documents its public API.
Model
Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
Method
declarations
go here.
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.h
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
Model
#import <Foundation/Foundation.h>
- (void)setOperand:(double)anOperand;
- (double)performOperation:(NSString *)operation;
@end Stanford
CS193p
Fall 2010
CalculatorBrain.m This is the implementation file.
Both public and private implementation
goes here. Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
@implementation CalculatorBrain
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
- (void)setOperand:(double)anOperand
{
<code goes here>
}
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
}
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
} Square brackets mean “send a message.”
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
}
@end This is the object to send the message to
Stanford
(in this case, the NSString called “operation” that was
CS193p
passed as an argument to performOperation:). Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
} This is the message to send.
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
} And this is its one (in this case) argument.
@end
Stanford
CS193p
Fall 2010
CalculatorBrain.m
Model
#import “CalculatorBrain.h”
@implementation CalculatorBrain
- (void)setOperand:(double)anOperand
{
operand = anOperand;
}
- (double)performOperation:(NSString *)operation
{
[operation sendMessage:argument];
return aDouble;
}
@end
Stanford
CS193p
Fall 2010
Controller
#import <UIKit/UIKit.h>
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operationPressed:(UIButton *)sender;
Stanford
@end CS193p
Fall 2010
Controller
Our Controller inherits from
UIViewController. UIKit
supports MVC primarily
#import <UIKit/UIKit.h> through this class.
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operationPressed:(UIButton *)sender;
Stanford
@end CS193p
Fall 2010
Controller
#import <UIKit/UIKit.h>
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operationPressed:(UIButton *)sender;
Stanford
@end CS193p
Fall 2010
These hook up to our View
Controller
#import <UIKit/UIKit.h>
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operationPressed:(UIButton *)sender;
Stanford
@end CS193p
Fall 2010
View
Controller
#import <UIKit/UIKit.h>
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operationPressed:(UIButton *)sender;
Stanford
@end CS193p
Fall 2010
Stanford
CS193p
CalculatorViewController.xib
Fall 2010
“File’s Owner” is our
Controller Stanford
CS193p
CalculatorViewController.xib
Fall 2010
Stanford
CS193p
Fall 2010
Stanford
CS193p
Fall 2010
Stanford
CS193p
Fall 2010
My First Project
Stanford
CS193p
Fall 2010