ラッパークラス
あなたはあなたの要求のためのラッパーを作成することができます。
class AlamofireWrapper {
static func request(/*all the params you need*/) {
if tokenIsValidated() { //perform your web token validation
Alamofire.request//...
.respone { /*whatever you want to do with the response*/ }
}
}
}
同じコードをもう一度コピーして貼り付ける必要はありません。
AlamofireWrapper().request(/*params*/)
拡張
これはテストされていません。あなたは
extension Alamofire {
func validatedRequest(/*all the params you need*/) {
if tokenIsValidated() { //perform your web token validation
Alamofire.request//...
.respone { /*whatever you want to do with the response*/ }
}
}
}
をAlamofire、あなたはすべてのコールに共通ヘッダを添付しようとしている場合は、この
Alamofire.validatedRequest(/*params*/)
呼び出しているAlamofireメソッドの周りにラッパーを作成しますか? – nhgrif