fastred / IBAnalyzer

Find common xib and storyboard-related problems without running your app or writing unit tests.
http://holko.pl
MIT License
951 stars 26 forks source link

Analyzer doesn't recognise IBOutlets hooked up in Objective-C super classes #21

Open rustyshelf opened 7 years ago

rustyshelf commented 7 years ago

Suppose you have a class: BaseCell, and it has a child FancyCell. You can hook IBOutlets from the childs XIB to the parent class, but the IBAnalyzer doesn't seem to find these, it will instead print out: FancyCell doesn't implement a required @IBOutlet named: starredView.

To be honest I'm not sure if this is a common use case, but I thought I'd note it here in case it helps.

fastred commented 7 years ago

Thanks for taking the time to report the issue!

If I understand correctly this case is covered in this unit test. In there we've got:

Hard to tell what exactly is wrong but I suspect it may be one of these:

I'm planning to add a better error reporting which should make debugging issues like this easier in the future.

rustyshelf commented 7 years ago

You are correct, and yes, the base class is Objective-C hence it wasn't picked up. Makes perfect sense considering the tool does Swift only. I should have figured that out, sorry! 😂

vhosune commented 7 years ago

I have seen the same issue, I but all @IBOutlet are not found. I have a separate storyboard, and a UIViewController with IBOutlet referencing a view in the UIViewController and another view outside the UIViewController but linked to it and with its @IBOutlet reference in the UIViewController source

ldiqual commented 7 years ago

Same issue here, we link a tableView outlet to a subclass of XLFormViewController (https://github.com/xmartlabs/XLForm), which is a third-party objC library. It seems that many people will run into this issue even if they have a 100% swift codebase but with objC third party frameworks (I guess that makes it not 100% swift then, hmmm).

fastred commented 7 years ago

@ldiqual Yeah, we should look into that. Here's a possible approach:

  1. Add ObjectiveCParser class, with the same public interface as SwiftParser. We could probably leverage some 3rd party library for tokenization, e.g. pegkit. It would have to operate on both .h and .m (and possibly .mm) files.
  2. Call it from Runner passing classNameToClassMap inout variable to it.

It's a big task but possibly pretty interesting to work on.

andywarwick commented 7 years ago

Think I am seeing the same thing. Am subclassing a UICollectionViewController which has a collectionView IBOutlet you set in IB. This causes a warning: IBOutlet missing: collectionView is not implemented in MySubclass.storyboard. Obviously this IBOutlet isn't in my subclass, and seems to be no way of ignoring the error.

pokchy commented 6 years ago

In Xcode 9.2 and Swift 4 there is the same issue. I got a parent and child class both have IBOutlets. My view with IBOutlets is of class from the child. Connecting in Interface Builder is no problem.

After compiling code there is this warning: IBOutlet unused in the parent class.