一、对象初始化
Person.h
#import<Foudation/Foudation.h>
@interface:NSObject
{
NSString *_name;
NSInteger _age;
}
-(id)initWithName:(NNString *)name withAge: Integer age;
-(void)showInfo;
@end
Person.m
#import "Person.h"
@implementation Person
-(id)initWithNmae:(NNString *)name withAge:(NSInteger)age{
if(self =[super init])
{
_name=name;
_age=age;
}
return self;
-(void)test
{
NSLog(@"test");
}
-(void)showInfo
{
NSLog(@"name is %s and age is %d",_name,_age)
}
}
main.m
#import <Foudation/Foudation.h>
#import "Person.h"
int main(int argc,const charchar *argv[]){
@autoreleasepol{
Person *person=[[Person alloc]init];
[person initWithName:@"zhangshan" withAge:22];
[person showInfo];
}
return 0;
}