一、类简介
类是定义一组集合---包含(属性和变量 方法)。
2.1 新建类文件
2.2 生成testClass.h testClass.m文件
/*testClass.h 类定义文件*/
#import < Foundation / Foundation.h >
@interface testClass : NSObject
{
NSString *name1; //成员变量定义(默认成员变量为protected属性)
NSNumber *age; //成员变量定义
NSString *info1; //成员变量定义
}
-(void)setName1:(NSString *) n; //成员方法
+(void)printInfo; //类方法 类似于其它语言中的静态方法(static)
@end
/*testClass.m 类实现文件*/
#import "testClass.h"
@implementation testClass
/*实现类*/
-(void)setName1:(NSString *) n{
name1 = @"123456";
}
+(void)printInfo{
NSLog(@"print name");
}
@end