Lets say I have a UIView
subclass with a generic constraint:
class CustomView<DataType: Codable>: UIView {
var model: DataType?
}
And I want to load this view from IB
This crashes the application: "Unknown class _TtC5Test110CustomView in Interface Builder file". This obviously has to do with the fact that IB knows nothing of the type it needs to pass for the generic constraint to meet the requirement. I could simply instantiate the view in code and pass the constraint type. But I wonder if there might be a workaround so the view could still be loaded from IB.
But I wonder if there might be a workaround so the view could still be loaded from IB.
No, there isn’t. IB is Objective-C Cocoa. It cannot be made to see or manipulate a Swift generic.
IB knows nothing of the type it needs to pass for the generic constraint to meet the requirement
IB knows nothing of Swift generics at all. The fact that you were able to enter CustomView as your view class is itself a bug.