Skip to content

Commit

Permalink
Added return value URLSessionDataTask for OpenGraph.fetch to have the…
Browse files Browse the repository at this point in the history
… ability to cancel task if needed
  • Loading branch information
Mikhail Basbas authored and Mikhail Basbas committed Jan 24, 2020
1 parent 93d8393 commit 0170d49
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion OpenGraph/OpenGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public struct OpenGraph {

public let source: [OpenGraphMetadata: String]

public static func fetch(url: URL, headers: [String: String]? = nil, completion: @escaping (Result<OpenGraph, Error>) -> Void) {
@discardableResult
public static func fetch(url: URL, headers: [String: String]? = nil, completion: @escaping (Result<OpenGraph, Error>) -> Void) -> URLSessionDataTask {
var mutableURLRequest = URLRequest(url: url)
headers?.compactMapValues { $0 }.forEach {
mutableURLRequest.setValue($1, forHTTPHeaderField: $0)
Expand All @@ -19,6 +20,7 @@ public struct OpenGraph {
}
})
task.resume()
return task
}

private static func handleFetchResult(data: Data?, response: URLResponse?, completion: @escaping (Result<OpenGraph, Error>) -> Void) {
Expand Down

0 comments on commit 0170d49

Please sign in to comment.