// static func launch(req: BaseReq) -> BaseReq { // If you write like the one above, you will get: // Error: Protocol 'BaseReq' can only be used as a generic constraint because it has Self or associated type requirements. staticfunclaunch<U: BaseReq>(req: U) -> U { let s ="network return string" print(req)
req.obj(s)
return req } }
// Cannot specialize non-generic type // enum Result { enumResult<T> { case suc(T) case err(Error) }
let areq =AReq { (r) in switch r { case .suc(let s): // S is AObj, we can access s.a s.a case .err(let r): break } } areq.launch() // or Launch.launch(req: areq)
let breq =BReq { (r) in switch r { case .suc(let s): // S is BObj, we can access s.b s.b case .err(let r): break } } breq.launch() Launch.launch(req: breq) s