Last active
November 27, 2019 13:56
-
-
Save mcz9mm/c62fccaf08f983b3697bb74437ba0e06 to your computer and use it in GitHub Desktop.
Get Image Size from URL
This file contains 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
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