0

I seemed to have found another situation that causes the famous "Unknown class in Interface Builder file."

I tried fixing this problem using all the suggestions people posted in the plethora of other Q/A's regarding this bug and none of them worked.

I have stripped down the code as much as possible to isolate the problem. Here it is:

Code that causes error:

Class 1:

import UIKit

class TableViewControllerSubclass<T:Any>:UITableViewController{

}

Class 2:

import UIKit

class TableViewControllerSubclassChild:TableViewControllerSubclass<Int>{

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

Main StoryBoard has single UITableViewController that inherits from TableViewControllerSubclassChild. Here is a screen shot:

enter image description here

When I run the project as is I get the following output in the console:

2017-04-13 15:50:30.226 TableViewControllerBug[6087:165667] Unknown class _TtC22TableViewControllerBug32TableViewControllerSubclassChild in Interface Builder file.

and the breakpoint viewDidLoad is never hit.

Now if you remove the use of generics in both classes and run the project there is no output to the console and the breakpoint at viewDidLoad is hit.

Code that does NOT cause error

NewClass 1:

import UIKit

class TableViewControllerSubclass:UITableViewController{

}

NewClass 2:

import UIKit

class TableViewControllerSubclassChild:TableViewControllerSubclass{

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

Here is the project with the code

My questions:

  1. Is this a bug with Xcode/Interface builder? Or does the problem stem from illegal use of generics?

  2. If this is illegal use of generics how does go about using generics properly in this situation?

  3. If this is a bug, does anyone know of a work around?

Any insight into the problem will help! Thanks!

J.beenie
  • 861
  • 10
  • 22
  • Hi I have the same issue did you figure out something ? – Jeremy Piednoel Jun 09 '17 at 15:58
  • The problem is that objective-C does not support generics and UITableViewController is an objective-C object (inherits from NSObject). So this is essentially an illegal use of generics. You can use generics on any object that inherits from NSObject. – J.beenie Jun 09 '17 at 19:17
  • 1
    Yes thanks beenie, I've read that here : https://stackoverflow.com/a/27608442/2046106 i put the link in case of someone needs it. – Jeremy Piednoel Jun 10 '17 at 19:38
  • Yup that's exactly it. – J.beenie Jun 12 '17 at 03:06

0 Answers0