我想檢查statusCode是否等於2xx,但是我不太清楚如何爲這種類型的錯誤處理創建這個正則表達式代碼。這是我的代碼在這個時候與一個變量,從頭檢索statusCode?使用statusCode處理錯誤
func SignUpWithPassword(email: String, password: String, delegate: CreateUserDelegate) {
testProvider.request(.SignIn(email, password), completion: { result in
switch result {
case let .Success(response):
let statusCode = response.statusCode
case let .Failure(error):
print(error)
let description = "Error! Please try again!"
delegate.CreateUser(didError: description)
}
})
delegate.CreateUser(didSucceed: SignUpUser(email: email, password: password))
}
感謝Kumar,正則表達式肯定是一種正確而有效的方式來比較整數值與範圍! –
@tamás-zahola ..歡迎... –
@tamás-zahola,我爲您優化了代碼..現在就試試.. –