I studied about generics but i still have no understanding, why to use them, when we can use protocols instead?
For example, examine following function:
public static func delete<T>(entity: T, auth: Auth) -> Observable<Void> where T: MSRequestEntity, T: DictConvertable {
// function do something
}
Ok, we have generic entity T, that is conform to MSRequestEntity and DictConvertable.
But we can simply rewrite this like that:
public static func delete(entity: MSRequestEntity & DictConvertable, auth: Auth) -> Observable<Void> {
// function do something
}
So, my question is, in what case should i use generics? All of situations i have imaging could easily be handled with protocols.