我正试图找出另一种方法来做这样的事情,使用范围运算符.
guard let statusCode = (response as? HTTPURLResponse)?.statusCode,statusCode >= 200 && statusCode <= 299 else {return}
也许是这样的:
guard let statusCode = (response as? HTTPURLResponse)?.statusCode where (200...299).contains(statusCode) else {return}
要么
guard let statusCode = (response as? HTTPURLResponse)?.statusCode,statusCode case 200...299 else {return}
这在Swift中可能吗?
随你心意:
原文链接:https://www.f2er.com/swift/318633.htmlguard let statusCode = (response as? HTTPURLResponse)?.statusCode,(200...299).contains(statusCode) else {return}
要么:
guard let statusCode = (response as? HTTPURLResponse)?.statusCode,case 200...299 = statusCode else {return}
要么:
guard let statusCode = (response as? HTTPURLResponse)?.statusCode,200...299 ~= statusCode else {return}