IBAnalyzer icon indicating copy to clipboard operation
IBAnalyzer copied to clipboard

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

Open rustyshelf opened this issue 8 years ago • 7 comments

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.

rustyshelf avatar Feb 05 '17 23:02 rustyshelf

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:

  • parent class A with @IBOutlet named label
  • subclass of A named B without any outlets
  • nib for the B class

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

  • a base class wasn't found and parsed (e.g. it's in a different folder or written in Objective-C)
  • the relationship between base and subclass wasn't established (not sure why this would happen)
  • the property wasn't found (I saw one report about outlets/actions in extensions) or parsed as an outlet (e.g. it's not annotated with the @IBOutlet attribute)

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

fastred avatar Feb 07 '17 22:02 fastred

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! 😂

rustyshelf avatar Feb 08 '17 00:02 rustyshelf

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

vhosune avatar Feb 21 '17 16:02 vhosune

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).

ldiqual avatar Feb 23 '17 01:02 ldiqual

@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.

fastred avatar Feb 23 '17 09:02 fastred

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.

andywarwick avatar May 25 '17 15:05 andywarwick

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.

pokchy avatar Feb 01 '18 17:02 pokchy