How does one instantiate a generics-supported UIViewController subclass?

How does one instantiate a generics-supported UIViewController subclass?


For example, consider a class like

class SpecialViewController<T: UIView> : UIViewController{ }


Interface Builder does not seem to handle these (in neither Storyboards nor simple .xibs)

Furthermore, the default initializers seem to no longer be inherited (init, init(withNibName: String, bundle: ...), and even init(style: UITableViewStyle) for UITableViewController subclasses)


Are there any known workarounds?

Objective-C can't import Swift generic classes or methods, and since UIKit expects classes to be fully compatible w/ objC you would have a tough time trying to getting generic subclasses to work.


I haven't tried to use Swift generics mixed with objective-c much myself, but some people have had luck using a simple Swift subclass of the objC class as a wrapper with a "clean" obj-c compatible interface, which encapsulates one or more instances of generic types and has implementations of the necessary overrides and delegate methods which forward the calls to the encapsulated generic type instances.

Hi,


I have the same problem.


With XCode 7 beta 2 we can write like this.


class SubSubViewController :SpecialViewController<String> {...


But I cannot specify the SubSubViewController a view controller in storyboard.


The following code won't work.


let vc = storyboard.instantiateViewControllerWithIdentifier("myid") as! SpecialViewController<String>
let vc = storyboard.instantiateViewControllerWithIdentifier("myid") as! SubSubViewController


Any idea?

Same here. I can see why using generic view controllers directly won't work in a storyboard (compiler checks for the generic part cannot be performed), but the concrete subclass should work IMHO.

Has anyone already filed a radar for this?

How does one instantiate a generics-supported UIViewController subclass?
 
 
Q