美文网首页
runtime-API-imp

runtime-API-imp

作者: Berning | 来源:发表于2023-11-13 18:02 被阅读0次

    1.通过block获取imp

        IMP imp_block = imp_implementationWithBlock(^{
            NSLog(@"do something");
        });
        
        BOOL is_add = class_addMethod(NSPerson.class, @selector(travel), imp_block, "v@:");
        if(is_add)
        {
            [NSPerson.new travel];
        }
    

    2.通过imp 获取block

        id block = imp_getBlock(imp_block);
        NSLog(@"%@",block);
    

    3.移除block

        BOOL is_removed = imp_removeBlock(imp_block);
        NSLog(@"is_removed:%d",is_removed);
    
    

    相关文章

      网友评论

          本文标题:runtime-API-imp

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