From c04f941eea250f78f5c7151c03cd2489ca9ffc2b Mon Sep 17 00:00:00 2001 From: Zach Eriksen Date: Wed, 17 Mar 2021 14:13:01 -0500 Subject: [PATCH] Added canImport(Combine) --- Sources/SURL/URL+.swift | 12 +++++------- Sources/SURL/URLRequest+.swift | 13 ++++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Sources/SURL/URL+.swift b/Sources/SURL/URL+.swift index 95b398b..2a8f75a 100644 --- a/Sources/SURL/URL+.swift +++ b/Sources/SURL/URL+.swift @@ -15,11 +15,6 @@ public extension URL { URLSession.shared.dataTask(with: self) } - @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) - var dataTaskPublisher: URLSession.DataTaskPublisher { - URLSession.shared.dataTaskPublisher(for: self) - } - func dataTask(withHandler handler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { URLSession.shared.dataTask(with: self, completionHandler: handler) } @@ -123,12 +118,15 @@ public extension URL { request.dataTask(withHandler: handler).resume() } - } +#if canImport(Combine) // MARK: URL HTTPRequestMethod DataTaskPublishers @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public extension URL { + var dataTaskPublisher: URLSession.DataTaskPublisher { + URLSession.shared.dataTaskPublisher(for: self) + } func get() -> URLSession.DataTaskPublisher { urlRequest(forHTTPMethod: .GET).dataTaskPublisher @@ -181,5 +179,5 @@ public extension URL { return request.dataTaskPublisher } - } +#endif diff --git a/Sources/SURL/URLRequest+.swift b/Sources/SURL/URLRequest+.swift index 57c1636..f58a1bf 100644 --- a/Sources/SURL/URLRequest+.swift +++ b/Sources/SURL/URLRequest+.swift @@ -29,13 +29,16 @@ public extension URLRequest { URLSession.shared.dataTask(with: self) } + func dataTask(withHandler handler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { + URLSession.shared.dataTask(with: self, completionHandler: handler) + } +} + +#if canImport(Combine) +public extension URLRequest { @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) var dataTaskPublisher: URLSession.DataTaskPublisher { URLSession.shared.dataTaskPublisher(for: self) } - - - func dataTask(withHandler handler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask { - URLSession.shared.dataTask(with: self, completionHandler: handler) - } } +#endif