您当前的位置: 首页 >  objective-c

清风清晨

暂无认证

  • 1浏览

    0关注

    71博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【autorelease的类方法的两点规范 Objective-C语言】

清风清晨 发布时间:2022-08-18 17:34:44 ,浏览量:1

前言

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]) {

关注
打赏
1663943137
查看更多评论
立即登录/注册

微信扫码登录

0.0349s