I have a class that intends to return a class which conforms to PanelControllerProtocol. The problem I'm having is taking the anyClass object and converting it to T.
func classFromBundle<T: PanelControllerProtocol>(className: String) -> T {
let bundleClassString = classBundleAndName(className)
var anyClass : AnyClass = NSClassFromString(bundleClassString)
}
If I try this:
var panelControllerType = anyClass as T
I get:
"Cannot cast from concrete type 'AnyClass' to type variable 'T' for which it does not match constraints".
Attempting to simply return anyClass gives me the error:
'AnyClass' is not convertible to 'T'
Trying to change my method name to this:
func classFromBundle<T where T: AnyClass, T: PanelControllerProtocol>(className: String) -> T
Gives the error:
Type 'T' constrained to non-protocol type 'AnyClass'
Also, once I figure out how to return the correct object, I'm not sure how to call the class. Currently, calling the above method like so:
classFromBundle("Test")
Gives the error:
Cannot convert the expression's type 'NSString' to type 'String'