如何查看状态码是否为200?

时间:2019-07-29 06:02:53

标签: swift nsurlsession

如何检查状态码是否为200。我想用快速的语言来做

session.dataTask(with: request){(data,response,error) in

            if let  response = response {
               print(response)

             }
           }

1 个答案:

答案 0 :(得分:0)

let statusCode: Int? = {
    if let httpUrlResponse = response as? HTTPURLResponse {
        return httpUrlResponse.statusCode
    }
    return nil
}()

然后将其与200进行比较