description方法
来源:互联网 发布:数据情报 编辑:程序博客网 时间:2024/05/02 05:04
OC中的description 方法和Java toString 方法类似,都是用来对对象实行串行化输出
@interface Student : NSObject@property(nonatomic)NSString *name;@end@implementation Student@end
这段代码简单的自定义了一个类
如果对该类的一个对象用NSLog输出
Student *student=[[Student alloc]init]; student.name=@"zhangsan"; NSLog(@"%@",student);
结果如下
<Student: 0x100100320>在自定义类中覆盖description方法
@interface Student : NSObject@property(nonatomic)NSString *name;-(NSString *)description;@end@implementation Student-(NSString *)description{ return self.name;}@end输出结果
zhansan
description方法是NSObject类中定义的,覆盖继承的description方法可以实现格式化字符显示类对象,在java中toString方法功能相同。
0 0
- description方法
- description方法
- description方法
- description方法
- description方法
- description 方法
- description方法
- description方法
- description方法
- description方法
- description方法
- 【description】方法
- description方法重载问题
- 【OC】OC description方法
- description方法及重写
- 重写description方法
- Objective-C - description 方法
- OC中的description方法
- Flume-ng 1.5部署,hadoop联合使用
- c# 多线程 --Mutex(互斥锁)
- dojo入门笔记2
- Objective-C基础(面向对象--下--三大特性--继承、多态)
- Mybatis及与spring集成入门实例
- description方法
- C/C++ 字符串处理小函数(个人总结)
- TortoiseSVN 日常操作指南
- 顺序表实现队列-栈
- Android官方入门文档[3]构建一个简单的用户界面
- Excel中经纬度数据转换公式
- Android 系统的自启动原理
- ACM-选夫婿(结构体排序练习)
- 对qucik cocos2dx lua SocketTCP的再一次封装,导入全局实例,包含自定义事件