首页 > 移动平台 > 详细

IOS 随记

时间:2015-07-26 17:16:05      阅读:257      评论:0      收藏:0      [点我收藏+]

1、自定义构造方法

- (id) initWithAge:(int)age andNo:(int)no {

    // 首先要调用super的构造方法

    // self = [super init];

    if (self = [super init]) {

         _age = age;

         _no = no;

    }

    return self;

}

 

2、重写父类的description方法

在entity中重写父类description 方法,在NSLog(@"%@",entity)打印entity时不再显示内存地址,而是显示description 返回的字符串。

- (NSString *)description {

    NSString *str = [NSString stringWithFormat:@"age is %i and no is %i", self.age, self.no];

    return str;

}

IOS 随记

原文:http://www.cnblogs.com/duke-cui/p/4678072.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!