以下のように通信に関する基底プロトコルを作ったとします。
Swift
1protocol Request { 2 associatedType Response: Decodable 3 var baseURL: URL { get } 4 var path: String { get } 5}
アプリが参照するURLのドメインが2種類(abc.com / def.com)以上あった時にプロトコルを継承した基底structを2つ作って、それを継承して各APIのstructを作りたいと考えています。
質問したいのは、基底structでのtypealiasの扱いで、基底structで型定義をしないで済む方法は何かありますでしょうか?
Swift
1struct ABCRequest: Request { 2 typealias Response = XXX <- ここで型指定させたくない 3} 4struct DEFRequest: Request { 5 typealias Response = XXX <- ここで型指定させたくない 6} 7 8struct ABC1Request: AbcRequest { 9 typealias Response = ABC1 10} 11struct ABC2Request: AbcRequest { 12 typealias Response = ABC2 13} 14struct DEF1Request: DEFRequest { 15 typealias Response = DEF1 16} 17
structは継承できません。
あと、コードが雑です。もう少し丁寧に書いて下さい。
![guest](/img/icon/icnUserSample.jpg)
あなたの回答
tips
プレビュー