Unfortunately, it can not be generic.
/// Represents an HTTP task.
public enum Task {
case requestPlain
case requestData(Data)
/// A request body set with `Encodable` type
case requestJSONEncodable(Encodable)
}
Task is used in different network providers, it is impossible to make it generic, such as Task<T>
.
In case we use requestJSONEncodable(Encodable), we use type erased Encodable. But try encoder.encode(value)
function needs a concrete Type, so type erasure struct is needed.
For more details, see Moya: GitHub - Moya/Moya: Network abstraction layer written in Swift.