📜  快速从 url 获取文件大小 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:01.897000             🧑  作者: Mango

代码示例2
extension URL {
    func fileSizeInMB() -> Double {
        var fileSize: Double = 0.0
        var fileSizeValue = 0.0
        try? fileSizeValue = (self.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!
        if fileSizeValue > 0.0 {
            fileSize = (Double(fileSizeValue) / (1024 * 1024))
        }
        return fileSize
    }
}