Skip to content

Commit

Permalink
Merge pull request #94 from m-herold/DVR-93
Browse files Browse the repository at this point in the history
Fix "[Session defaultTaskGroup]: unrecognized selector sent to instance" for Swift 5.1 (#93)
  • Loading branch information
dmiluski committed Sep 24, 2019
2 parents 9b60014 + 6063f41 commit 77d681e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/DVR/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ open class Session: URLSession {


// MARK: - URLSession

open override func dataTask(with url: URL) -> URLSessionDataTask {
return addDataTask(URLRequest(url: url))
}

open override func dataTask(with url: URL, completionHandler: @escaping ((Data?, Foundation.URLResponse?, Error?) -> Void)) -> URLSessionDataTask {
return addDataTask(URLRequest(url: url), completionHandler: completionHandler)
}

open override func dataTask(with request: URLRequest) -> URLSessionDataTask {
return addDataTask(request)
Expand Down
26 changes: 26 additions & 0 deletions Tests/DVRTests/SessionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ class SessionTests: XCTestCase {
XCTFail()
}
}

func testDataTaskWithUrl() {
let url = URL(string: "http://example.com")!
let dataTask = session.dataTask(with: url)

XCTAssert(dataTask is SessionDataTask)

if let dataTask = dataTask as? SessionDataTask, let headers = dataTask.request.allHTTPHeaderFields {
XCTAssert(headers["testSessionHeader"] == "testSessionHeaderValue")
} else {
XCTFail()
}
}

func testDataTaskWithUrlAndCompletion() {
let url = URL(string: "http://example.com")!
let dataTask = session.dataTask(with: url, completionHandler: { _, _, _ in return })

XCTAssert(dataTask is SessionDataTask)

if let dataTask = dataTask as? SessionDataTask, let headers = dataTask.request.allHTTPHeaderFields {
XCTAssert(headers["testSessionHeader"] == "testSessionHeaderValue")
} else {
XCTFail()
}
}

func testPlayback() {
session.recordingEnabled = false
Expand Down

0 comments on commit 77d681e

Please sign in to comment.