ios - Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
PHP中文网
PHP中文网 2017-04-18 09:56:08
0
1
516

Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式

PHP中文网
PHP中文网

认证高级PHP讲师

Antworte allen(1)
小葫芦

不一定非写分类,你调下面的方法进行方法交换,位置不随便写吗?

void methodSwizzle(Class c, SEL orig, SEL newS )
{
    Method origMethod = class_getInstanceMethod(c, orig);
    Method newMethod = class_getInstanceMethod(c, newS);
    
    BOOL addSuccess = class_addMethod(c, orig, method_getImplementation(newMethod),method_getTypeEncoding(newMethod) );
    
    if (addSuccess) {
        class_replaceMethod(c, newS, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
        
    }else{
        method_exchangeImplementations(origMethod, newMethod);
        
    }
    
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!