.h文件
#import <Foundation/Foundation.h>
@interface Time3 : NSObject//类方法实现
{
int hour;
int minute;
int second;
}
-(void)setHour:(int)_h;
-(int)hour;
-(void)setMinute:(int)_m;
-(int)minute;
-(void)setSecond:(int)_s;
-(int)second;
+(Time3 *)creat;
@end
.m文件
#import "Time3.h"
@implementation Time3
-(void)setHour:(int)_h
{
hour = _h;
}
-(int)hour
{
return hour;
}
-(void)setMinute:(int)_m
{
minute = _m;
}
-(int)minute
{
return minute;
}
-(void)setSecond:(int)_s
{
second = _s;
}
-(int)second
{
return second;
}
+(Time3 *)creat;
{
Time3 *time = [[Time3alloc]init];
return time;
}
主函数
#import <Foundation/Foundation.h>
#import "Time3.h"
int main(int argc,const char * argv[])
{
@autoreleasepool {
// insert code here...
Time3 *time = [Time3creat];//类方法
[timesetHour:10];
[timesetMinute:20];
[timesetSecond:30];
NSLog(@"%d:%d:%d",[timehour],[time minute],[timesecond]);
}
return 0;
}