定义方法:
#import <Foundation/Foundation.h> @interface Model : NSObject @property (strong,nonatomic) NSString *name; @property (strong,nonatomic) NSString *age; +(Model*)initWithName:(NSString*)name AndAge:(NSString*)age; @end
#import "Model.h" @implementation Model +(Model*)initWithName:(NSString *)name AndAge:(NSString *)age { static Model *model=nil; if (model==nil) { model=[[Model alloc]init]; model.name=name; model.age=age; } return model; } @end
调用的时候:
在一个类中: Model *model =[Model initWithName:@"testName1" AndAge:@"1"];
在另一个类中:Model *model =[Model initWithName:@"testName2" AndAge:@"2"];
结果: testName1 1