Created
September 6, 2020 09:11
-
-
Save agammahajan1/944bb95257681d50667d578ad63af121 to your computer and use it in GitHub Desktop.
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("FileAttribute error: \(error)") | |
} | |
return nil | |
} | |
var fileSize: UInt64 { | |
return attributes?[.size] as? UInt64 ?? UInt64(0) | |
} | |
var fileSizeString: String { | |
return ByteCountFormatter.string(fromByteCount: Int64(fileSize), countStyle: .file) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment