Skip to content

Commit

Permalink
Added canImport(Combine)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Eriksen committed Mar 17, 2021
1 parent 2ad0e8a commit c04f941
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 5 additions & 7 deletions Sources/SURL/URL+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -181,5 +179,5 @@ public extension URL {

return request.dataTaskPublisher
}

}
#endif
13 changes: 8 additions & 5 deletions Sources/SURL/URLRequest+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c04f941

Please sign in to comment.