The response parameter is of type
AutoreleasingUnsafeMutablePointer<NSURLResponse?>
which means you can pass the address of an optional argument NSURLResponse
as an argument:
var response : NSURLResponse?
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response , error: nil)
Then you can conditionally discard the returned answer to NSHTTPURLResponse
:
if let httpResponse = response as? NSHTTPURLResponse {
println(httpResponse.expectedContentLength)
}
Please note that you must check the return value sendSynchronousRequest()
, which
nil
if the connection cannot be completed.
( sendAsynchronousRequest()
)
- , -
.