I have the following class in Swift:
public class EffectModel {
var type:String
var keyframeGroup:[Keyframe<EffectParam>] = []
}
public enum EffectParam<Value:Codable>:Codable {
case scalar(Value)
case keyframes([Keyframe<Value>])
public enum CodingKeys: String, CodingKey {
case rawValue, associatedValue
}
...
...
}
public class Keyframe<T:Codable> : Codable {
public var time:CMTime
public var property:String
public var value:T
enum CodingKeys: String, CodingKey {
case time
case property
case value
}
...
}
The problem is compiler doesn't accepts the generic EffectParam and gives the error
Generic parameter 'Value' could not be inferred
One way to solve the problem would be to redeclare the class EffectModel as
public class EffectModel <EffectParam:Codable>
But the problem is this class has been included in so many other classes so I will need to incorporate generic in every class that has object of type EffectModel, and then any class that uses objects of those classes and so on. That is not a solution for me. Is there any other way to solve the problem in Swift using other language constructs (such as protocols)?