Last active
March 22, 2019 17:25
-
-
Save olejorgensen/da506ffa62e5aa36749b243e01210a0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// URLResponse+Extensions.swift | |
// | |
import Foundation | |
extension URLResponse { | |
var lastModifiedHeader: String? { | |
get { | |
if let httpResp = self as? HTTPURLResponse, let lastMod = httpResp.allHeaderFields["Last-Modified"] as? String { | |
return lastMod | |
} | |
return nil | |
} | |
} | |
var lastModified: Date? { | |
get { | |
guard let lastModifiedHeader = self.lastModifiedHeader else { return nil } | |
let gmtDateFormatter = DateFormatter() | |
gmtDateFormatter.dateFormat = "EEEE, dd LLL yyyy HH:mm:ss zzz" | |
return gmtDateFormatter.date(from: lastModifiedHeader) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment