From dbf094c4f40422bb9390c2407cab98c6bd91e0c3 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Wed, 17 Jan 2024 11:59:22 +1300 Subject: [PATCH 1/2] Remove `Progress.sessionTask` The API isn't used in neither the library nor the apps --- WordPressKit/WordPressComRestApi.swift | 22 ---------------------- WordPressKit/WordPressOrgRestApi.swift | 1 - 2 files changed, 23 deletions(-) diff --git a/WordPressKit/WordPressComRestApi.swift b/WordPressKit/WordPressComRestApi.swift index a6dc93121..06e3f8261 100644 --- a/WordPressKit/WordPressComRestApi.swift +++ b/WordPressKit/WordPressComRestApi.swift @@ -63,8 +63,6 @@ open class WordPressComRestApi: NSObject { @objc public static let LocaleKeyDefault = "locale" // locale is specified with this for v1 endpoints @objc public static let LocaleKeyV2 = "_locale" // locale is prefixed with an underscore for v2 - @objc public static let SessionTaskKey = "WordPressComRestAPI.sessionTask" - public typealias RequestEnqueuedBlock = (_ taskID: NSNumber) -> Void public typealias SuccessResponseBlock = (_ responseObject: AnyObject, _ httpResponse: HTTPURLResponse?) -> Void public typealias FailureReponseBlock = (_ error: NSError, _ httpResponse: HTTPURLResponse?) -> Void @@ -225,7 +223,6 @@ open class WordPressComRestApi: NSObject { failure(processedError ?? (error as NSError), response.response) } }).downloadProgress(closure: progressUpdater) - progress.sessionTask = dataRequest.task progress.cancellationHandler = { [weak dataRequest] in dataRequest?.cancel() } @@ -606,25 +603,6 @@ private extension WordPressComRestApi { } } -// MARK: - Progress - -@objc extension Progress { - - var sessionTask: URLSessionTask? { - get { - return userInfo[.sessionTaskKey] as? URLSessionTask - } - - set { - self.setUserInfoObject(newValue, forKey: .sessionTaskKey) - } - } -} - -extension ProgressUserInfoKey { - public static let sessionTaskKey = ProgressUserInfoKey(rawValue: WordPressComRestApi.SessionTaskKey) -} - // MARK: - POST encoding private extension Dictionary { diff --git a/WordPressKit/WordPressOrgRestApi.swift b/WordPressKit/WordPressOrgRestApi.swift index c9971bb26..b34bba058 100644 --- a/WordPressKit/WordPressOrgRestApi.swift +++ b/WordPressKit/WordPressOrgRestApi.swift @@ -70,7 +70,6 @@ open class WordPressOrgRestApi: NSObject, WordPressRestApi { } }).downloadProgress(closure: progressUpdater) - progress.sessionTask = dataRequest.task progress.cancellationHandler = { dataRequest.cancel() } From 299bf239d4efe6e155abc3a718f5f348c86bbeb9 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Thu, 18 Jan 2024 11:30:25 +1300 Subject: [PATCH 2/2] Rename parameter `fulfillingProgress: Progress` to `fulfilling: Progress` --- WordPressKit/HTTPClient.swift | 2 +- WordPressKitTests/Utilities/URLSessionHelperTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPressKit/HTTPClient.swift b/WordPressKit/HTTPClient.swift index c886e5435..b1978941f 100644 --- a/WordPressKit/HTTPClient.swift +++ b/WordPressKit/HTTPClient.swift @@ -44,7 +44,7 @@ extension URLSession { func perform( request builder: HTTPRequestBuilder, acceptableStatusCodes: [ClosedRange] = [200...299], - fulfillingProgress parentProgress: Progress? = nil, + fulfilling parentProgress: Progress? = nil, errorType: E.Type = E.self ) async -> WordPressAPIResult, E> { if let parentProgress { diff --git a/WordPressKitTests/Utilities/URLSessionHelperTests.swift b/WordPressKitTests/Utilities/URLSessionHelperTests.swift index a84705496..9e10f7ba5 100644 --- a/WordPressKitTests/Utilities/URLSessionHelperTests.swift +++ b/WordPressKitTests/Utilities/URLSessionHelperTests.swift @@ -116,7 +116,7 @@ class URLSessionHelperTests: XCTestCase { XCTAssertEqual(progress.completedUnitCount, 0) XCTAssertEqual(progress.fractionCompleted, 0) - let _ = await URLSession.shared.perform(request: .init(url: URL(string: "https://wordpress.org/hello")!), fulfillingProgress: progress, errorType: TestError.self) + let _ = await URLSession.shared.perform(request: .init(url: URL(string: "https://wordpress.org/hello")!), fulfilling: progress, errorType: TestError.self) XCTAssertEqual(progress.completedUnitCount, 20) XCTAssertEqual(progress.fractionCompleted, 1) } @@ -136,7 +136,7 @@ class URLSessionHelperTests: XCTestCase { } // The result should be an cancellation result - let result = await URLSession.shared.perform(request: .init(url: URL(string: "https://wordpress.org/hello")!), fulfillingProgress: progress, errorType: TestError.self) + let result = await URLSession.shared.perform(request: .init(url: URL(string: "https://wordpress.org/hello")!), fulfilling: progress, errorType: TestError.self) if case let .failure(.connection(urlError)) = result, urlError.code == .cancelled { // Do nothing } else {