woshiccm / Pecker

CodePecker is a tool to detect unused Swift code.
MIT License
1.46k stars 63 forks source link

Request: Blacklist @objc methods #21

Closed noahsark769 closed 4 years ago

noahsark769 commented 4 years ago

Since Pecker reports Swift methods that are only used by Obj-C code as unused, it would be nice to have an option to remove methods/properties annotated with @objc from reporting.

woshiccm commented 4 years ago

If Swift methods that are only used by Obj-C code, it will not report as unused.

@interface ThiredViewController ()

@end

@implementation ThiredViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    SecondViewController *vc = [[SecondViewController alloc] init];
    [vc secondtest:@1 name:@"roy"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @objc(secondtest: name:) // used
    func test(_ id: NSNumber, name: String) {

    }

}
noahsark769 commented 4 years ago

Huh, I thought I saw an example of this when I ran Pecker on our codebase. I’ll follow up with a concrete example when I can 👍

noahsark769 commented 4 years ago

Just following up, not sure what happened but I'm unable to reproduce anymore. Closing this