@impleme...">
美文网首页
runtime方法的交换

runtime方法的交换

作者: cj小牛 | 来源:发表于2016-06-06 17:11 被阅读22次

import "UIImage+image.h"

import <objc/message.h>

@implementation UIImage (image)

//+(UIImage*)imageNamed:(NSString *)name{
//// 在分类里面不能调用super
// return nil;
//}

// 运行时

// 1.先写一个其他的方法来实现这个
+(__kindof UIImage)CJimageNamed:(NSString)imageName{

// 1. 加载图片 (在运行时的是后这里调用相当于是调用imagewithname)
UIImage *image =[UIImage CJimageNamed:imageName];
// 2.判断图片是否为空

if (image == nil) {
    NSLog(@"加载的图片为空");
}
return image;

}
//加载分类的时候就会调用
+(void)load{
NSLog(@"%s",func);
// 交换方法
// 获取实例方法
// class_getInstanceMethod(<#__unsafe_unretained Class cls#>, <#SEL name#>)
获取对象的方法。
Method method1= class_getClassMethod([UIImage class], @selector(imageNamed:));

Method method2= class_getClassMethod([UIImage class], @selector(CJimageNamed:));

method_exchangeImplementations(method1, method2);

}

相关文章

  • runTime常用方法

    使用runTime改变实例成员的值 使用runtime来交换两个方法 注意再次调用该方法不交换 使用runTime...

  • runtime

    runtime交换方法 动态添加方法

  • Runtime

    runtime运行时机制1:通过runtime,实现方法交换(交换两个类方法、交换两个实例方法)2:通过runti...

  • Day3

    1 runtime运行时机制1:通过runtime,实现方法交换(交换两个类方法、交换两个实例方法)。2:通过ru...

  • runtime的理解(二)

    主要内容 利用 runtime 交换方法 利用 runtime 动态添加方法 利用 runtime 动态添加属性 ...

  • 查看SDK调用支付宝参数

    使用runtime 方法交换openurl

  • objc runtime (四)动态添加属性

    在《objc runtime (二)交换方法》中我提到过runtime最实用的就是交换方法和动态添加属性两个用法。...

  • iOS runtime如何交换两个类方法

    如有转载,请标明出处:iOS runtime如何交换两个类方法 runtime交换实例方法,老生常谈的问题,很多b...

  • ios-面试-runtime中黑魔法方法交换

    方法交换-原理 方法交换,传言中的runtime中的黑魔法! 依据runtime的机制,OC中类生成的对象在运行时...

  • runtime和oc内存区域(2018-04-02)

    runtime常用的几个方法: 交换方法 动态添加属性 动态添加方法 1.交换方法 class_getClassM...

网友评论

      本文标题:runtime方法的交换

      本文链接:https://www.haomeiwen.com/subject/vducdttx.html