Skip to content

Commit 2d80441

Browse files
authored
Merge pull request #635 from pushkarnk/sr2630
2 parents 96cf3a5 + c3041ed commit 2d80441

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Foundation/NSURLSession/NSURLSessionTask.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,13 @@ extension URLSessionTask {
839839
guard case .inMemory(let bodyData) = bodyDataDrain else {
840840
fatalError("Task has data completion handler, but data drain is not in-memory.")
841841
}
842+
842843
guard let s = session as? URLSession else { fatalError() }
843-
844-
var data = Data(capacity: bodyData!.length)
845-
data.append(Data(bytes: bodyData!.bytes, count: bodyData!.length))
844+
845+
var data = Data()
846+
if let body = bodyData {
847+
data = Data(bytes: body.bytes, count: body.length)
848+
}
846849

847850
s.delegateQueue.addOperation {
848851
completion(data, response, nil)

0 commit comments

Comments
 (0)