performSelector实现不引入头文件

或者以下方法也可以不用引入头文件

                    SEL action = NSSelectorFromString(@"Action_HuNormalizedTrainingDetailViewController:");
                    id target = [[NSClassFromString(@"Target_HuTrain") alloc] init];
                    NSMutableDictionary *params = @{}.mutableCopy;
                    params[@"ID"] = model.releationId;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                    UIViewController *vc =  [target performSelector:action withObject:params];
#pragma clang diagnostic pop

或者
1个参数

    UIViewController *vc = [HuNormalizedTrainingViewModel shareInstance].vc;
    SEL selector = NSSelectorFromString(@"refreshRecordNormalViewTableView");
    if (selector && [vc respondsToSelector:selector]) {
        SuppressPerformSelectorLeakWarning([vc performSelector:selector withObject:nil]);
    }

2个参数

UIViewController *vc = weakSelf.vc;
                    SEL selector = NSSelectorFromString(@"reloadRecordNormalViewTableView:withLoadMore:");
                    if (selector && [vc respondsToSelector:selector]) {
                        SuppressPerformSelectorLeakWarning([vc performSelector:selector withObject:dataSources withObject:@(YES)]);
                    }

NSClassFromString(@"HuStandardTrainViewController")

[_trainVC performSelector:NSSelectorFromString(@"setAAA:") withObject:NO afterDelay:0];

ps:宏定义

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。

你可能感兴趣的:(performSelector实现不引入头文件)