#import
@interface
}
@property(nonatomic) int x,y;
@end
sss.m:
#import "sss.h"
@implementation sss
@synthesize x,y;
//-(NSString *)description{
//
//
//}
@end
main函数:
#import
#import "sss.h"
int main(int argc, const char * argv[])
{
}
输出结果如下(没有重写description函数):
2013-04-09 17:15:31.787 147[281:303] Hello, World!
2013-04-09 17:15:31.789 147[281:303] 4,5
2013-04-09 17:15:31.789 147[281:303]
重写后的输出结果如下:
2013-04-09 17:16:54.189 147[294:303] Hello, World!
2013-04-09 17:16:54.191 147[294:303] 4,5
2013-04-09 17:16:54.191 147[294:303] xinglianting
本文介绍在Objective-C中如何通过重写description方法来定制对象的字符串表示形式。当使用NSLog打印对象时,若参数包含%@则会调用description方法。通过重写此方法,可以控制对象的具体输出格式。
1028

被折叠的 条评论
为什么被折叠?



