系统类,系统分类和自定义分类优先级
来源:互联网 发布:医学英语软件 编辑:程序博客网 时间:2024/06/14 13:27
在自定义的系统类(A)的分类中,重写A的系统属性和方法时,仍会优先调用系统的的属性和方法。重点内容 而重写A的系统分类的方法时,则会优先调用重写的方法。
例子:NSString
length 属性和 characterAtIndex:方法为系统方法,即使在自定义分类里重写,仍会优先调用系统的属性和方法
substringFromIndex: 方法是NSString的系统分类的方法,在自定义的分类里重写后,则会优先调用自定义的分类
NSString+test.h文件
@interface NSString (test)
/**
* 重写系统属性和方法
*/
- (NSUInteger)length;
- (unichar)characterAtIndex:(NSInteger)index;
/**
* 重写系统分类方法
*/
- (NSString *)substringFromIndex:(NSUInteger)from;
@end
NSString+test.m 文件
@implementation NSString (test)
- (NSUInteger)length
{
return 10;
} - (NSString *)substringFromIndex:(NSUInteger)from
{
return @”xxxxx”;
} - (unichar)characterAtIndex:(NSInteger)index
{
return ‘r’;
}
@end
main.m main函数里调用
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here…
NSString *str = @"Hello,everyone"; NSString *str1 = [str substringFromIndex:3]; unichar s = [str characterAtIndex:3]; NSLog(@"str.length : %ld",str.length); NSLog(@"str1 : %@",str1); NSLog(@"s : %c",s);}return 0;
}
输出结果为:
2017-07-13 22:34:10.831949+0800 MulInteranceDemo[10740:416546] str.length : 14
2017-07-13 22:34:10.831987+0800 MulInteranceDemo[10740:416546] str1 : xxxxx
2017-07-13 22:34:10.832004+0800 MulInteranceDemo[10740:416546] s : l
- 系统类,系统分类和自定义分类优先级
- 新闻资讯类系统 ---- 文章分类和标签的设计
- thuctc文本分类系统改写和使用
- 服务器系统的分类和介绍
- 浅谈企业信息系统分类
- 系统的分类
- GSM系统信道分类
- 系统表--分类说明
- [推荐系统]分类
- 数据分析系统分类
- 推荐系统算法分类
- 细胞分类 识别 系统
- xxxxxxclub系统模块分类
- iOS知识点系统分类
- 嵌入式系统分类
- Linux系统分类
- 后台管理系统分类
- 推荐系统分类
- C++各种常见排序算法
- 细说反射,Java 和 Android 开发者必须跨越的坎
- 【PAT】【Advanced Level】1010. Radix (25)
- CodeForces 575 A.Fibonotci(矩阵快速幂+线段树)
- VMware虚拟机备份和恢复
- 系统类,系统分类和自定义分类优先级
- C primer plus(编程练习)file-3.11-3
- HDFS常用命令
- VTK设置渐变背景色效果
- File类与IO流
- OpenGL学习——入门篇 第一章 环境搭建
- 22.广播BroadcastReceiver2
- Android布局
- 压缩数据减少网络交互量举例