Objectc 动态调用函数

项目设计到多个平台,所有底层函数名都是统一的,这就要求IOS这边的函数必须动态执行。

-(void)executefunction:(NSString *)funciontName
{
    NSLog(@"%@",funciontName);
    [self performSelector:(SEL)("test_function")];
    char *f="test_function";
    [self performSelector:(SEL)(f)];
    
    //使用NSString
    [self performSelector:NSSelectorFromString(funciontName)];
    //objc_msgSend(delegateObject, (SEL)method);
}
-(void)test_function
{
    NSLog(@"----fsdaf");
}


原文地址:https://www.cnblogs.com/bandy/p/2421663.html