johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 566 forks source link

Generic Classes #219

Open bolismauro opened 7 years ago

bolismauro commented 7 years ago

Hi, I read here https://github.com/johnno1962/injectionforxcode/issues/198 that the injection is not supposed to work for generic classes.

Is there a way to make it work, or is it enough to have a generic in the class hierarchy to disallow the injection? For instance

class GenericView<Model>: UIView { .. }

class RootView: GenericView<ConcreteModel> { .. }

doesn't work.

Thanks!

johnno1962 commented 7 years ago

Hi,

sorry, but Generic classes are not visible to the Objective-C runtime which injection relies on so this has proven not to be possible.

bolismauro commented 7 years ago

Alright, no problem :) I'll try to leverage (view) composition to get the effect I want

class ContainerView: GenericView<ConcreteModel> {
 // add innerview as subview
}

class InnerView: UIView {..}

it should work, right?