消除performSelector:警告的方法

performSelector:方法将会因为不知道它的选择器而导致内存泄露。ARC编译器会给出一个警告:

"performSelector may cause a leak because its selector is unknown"

可以利用IMP和函数指针方法配合解决:

 SEL selector = NSSelectorFromString(@"someMethod");
    IMP imp = [self methodForSelector:selector];
    void (*func)(id,SEL) = (void *)imp;
    func(self,selector);

你可能感兴趣的:(Bugs)