博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 的 runtime
阅读量:4605 次
发布时间:2019-06-09

本文共 990 字,大约阅读时间需要 3 分钟。

Runtime

运行时的使用:

1. KVO , KVC 

2. 运行过程中交换两个方法的实现,改系统的方法.

  例如:  当一个做了几年的项目要从iOS6适配到iOS7时,要把之前的图片全部换掉,可通过扩展UIImage 实现它的分类.补充一个类方法imageWithName: name.然后将系统的imageName:方法与imageWithName:name 的方法在运行时换掉,而不用修改其他代码.

#import "UIImage+Extension.h"#import 
@implement UIImage(Extension)+(void) load{ Method otherMethod = class_getClassMethod([UIImage class],@selector(imageWithName:)); Method originMethod = class_getClassMethod([UIImage class],@selector(imageNamed:)); //交换两个方法的实现 method_exchangeImplementations(otherMethod, originMethod);}+ (UIImage *) imageWithName:(NSString *) name{ BOOL ios7 = [[UIDevice currentDevice].systemVersion floatValue] >= 7.0; UIImage * image = nil; if (ios7) { NSString * newName = [name stringByAppendingString:@"_os7"]; image = [UIImage imageWithName:newName]; } if (image ==nil) { image = [UIImage imageWithName: name]; } return image;}@end

 

转载于:https://www.cnblogs.com/aunty/p/5141964.html

你可能感兴趣的文章
Wireless Network 并查集
查看>>
51nod 1019 逆序数
查看>>
20145202马超《JAVA》预备作业1
查看>>
云推送注意(MSDN链接)
查看>>
IDEA 生成 jar 包
查看>>
加减乘除混合版
查看>>
linux基础6-bash shell编程
查看>>
掌握这几种微服务模式助你成为更出色的工程师
查看>>
为什么很多语言选择在JVM上实现
查看>>
CSS Reset CSS Framework
查看>>
LeetCode算法扫题系列19
查看>>
nginx获取经过层层代理后的客户端真实IP(使用正则匹配)
查看>>
YII实现dropDownList 联动事件
查看>>
历届试题 高僧斗法
查看>>
linux命令系列 stat & touch
查看>>
[Tools] Webstorm Github的配置与使用
查看>>
鬼谷子绝学
查看>>
用Html5与Asp.net MVC上传多个文件
查看>>
Xcode中匹配的配置包的存放目录
查看>>
JavaScript将具有父子关系的原始数据格式化成树形结构数据(id,pid)
查看>>