Skip to content

Instantly share code, notes, and snippets.

@mcz9mm
Last active November 27, 2019 13:56
Show Gist options
  • Save mcz9mm/c62fccaf08f983b3697bb74437ba0e06 to your computer and use it in GitHub Desktop.
Save mcz9mm/c62fccaf08f983b3697bb74437ba0e06 to your computer and use it in GitHub Desktop.
Get Image Size from URL
extension URL {
var attributes: [FileAttributeKey : Any]? {
do {
return try FileManager.default.attributesOfItem(atPath: path)
} catch let error as NSError {
print(error)
}
return nil
}
var fileSize: UInt64 {
return attributes?[.size] as? UInt64 ?? UInt64(0)
}
var fileSizeString: String {
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file)
}
var creationDate: Date? {
return attributes?[.creationDate] as? Date
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment