//Tire.h 文件
#import <Cocoa/Cocoa.h>
@interface Tire : NSObject {
float pressure;
float treadDepth;
}
-
- (id) initWithPressure:(float) pressure;
-
- (id) initWithTreadDepth:(float) treadDepth;
-
- (id) initWithPressure:(float) pressuretreadDepth: (float) treadDepth;
-
- (void) setPressure: (float) pressure;
-
- (float) pressure;
-
- (void) setTreadDepth:(float) treadDepth; //指定的初始化函数
-
- (float) treadDepth;
@end // Tire
-
//Tire.m 文件#import "Tire.h"
@implementation Tire
- (id) init{
if (self = [self initWithPressure:34 treadDepth: 20]) {
}
return (self);
}-{
}
return (self);
// initWithPressure(id) initWithTreadDepth:(float) td
if (self = [self initWithPressure:34.0treadDepth: td]) {
}
return (self);
// initWithTreadDepth(id) initWithPressure:(float) ptreadDepth: (float) td
// init
(id) initWithPressure:(float) pif (self = [self initWithPressure:ptreadDepth: 20.0]) {
{
if (self = [super init]) {}
-{
pressure = p;
treadDepth = td;}
return (self);
// initWithPressure:treadDepth:(void) setPressure: (float) ppressure = p;
}-{
}
-{
}
-{
}
-{
}
// setPressure(float) pressure
return (pressure);// pressure
(void) setTreadDepth:(float) td
treadDepth = td;// setTreadDepth
(float) treadDepth
return (treadDepth);// treadDepth
(NSString *) description
NSString *desc;
desc = [NSString stringWithFormat:@"Tire: Pressure: %.1f TreadDepth: %.1f",pressure, treadDepth];
return (desc);// description
@end // Tire//*********************************************************************************
通常的写法:- (id)init{
if (self = [super...init])
{}
return (self) ;
}
-