前言
autorelease的规范: 0)创建对象,将对象存储到自动释放池之中,就不需要再去手动的release。
一、一般情况下,写1个类,会为我们的类写1个类方法,用来让外界调用类方法来快速的得到1个对象例如:有一个Pig类: @interface Pig : NSObject @property(nonatomic,retain)NSString *name; @property(nonatomic,assign)int age; @property(nonatomic,assign)float weight;
– (instancetype)initWithName:(NSString *)name andAge:(int)age andWeight:(float)weight;
++(instancetype)pig;
++(instancetype)pigWithName:(NSString *)name andAge:(int)age andWeight:(float)weight; @end
@implementation Pig – (void)dealloc { NSLog(@“猪挂了。。。”); [_name release]; [super dealloc]; } – (instancetype)initWithName:(NSString *)name andAge:(int)age andWeight:(float)weight { if(self = [super init]) {