zoukankan      html  css  js  c++  java
  • iOS 利用runtime调用方法

    利用runtime调用方法,可实现不做import,直接调用

    // Build Setting--> Apple LLVM 6.0 - Preprocessing--> Enable Strict Checking of objc_msgSend Calls  改为 NO

    - (void)execFunction2

    {

        NSString *functionName = @"runWithFriend:";

        NSString *className = @"People";

        NSString *friend = @"妹子";

        

        SEL runAction = NSSelectorFromString(functionName);

        Class peopleClass = NSClassFromString(className);

        

        objc_msgSend(peopleClass, runAction, friend);

    }

     

    static NSMutableDictionary *cache;

    - (void)execFunction

    {

        if (!cache)

            cache = [NSMutableDictionary dictionary];

        

        NSString *functionName = @"runWithFriend:";

        NSString *className = @"People";

        NSString *friend = @"妹子";

        

        SEL runAction = NSSelectorFromString(functionName);

        Class peopleClass = NSClassFromString(className);

        

        NSMethodSignature *runSig;

        if ([cache objectForKey:functionName]) {

            runSig = [cache objectForKey:functionName];

        } else {

        // methodSignatureForSelector:比较耗费性能, 所以最好把签名缓存起来

            runSig = [peopleClass methodSignatureForSelector:runAction];

            [cache setObject:runSig forKey:functionName];

        }

     

        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:runSig];

        

        [inv setSelector:runAction];

        [inv setArgument:&friend atIndex:2];

        [inv invokeWithTarget:peopleClass];

    }

  • 相关阅读:
    hadoop集群委任和解除节点
    hadoop参数
    HDFS启动及读写过程(读书笔记)
    hadoop QJM高可用原理
    十七、S3C2440裸机—IIC 接口
    十六、S3C2440裸机—UART
    十五、S3C2440裸机—系统时钟和定时器
    十四、s3c2440裸机—中断控制器
    四、NAND Flash
    二、存储管理器--SDRAM
  • 原文地址:https://www.cnblogs.com/oumygade/p/4641231.html
Copyright © 2011-2022 走看看