“Swift Obtenha o tamanho do arquivo do URL” Respostas de código

Tamanho do arquivo Swift da URL

do {
    let resources = try url.resourceValues(forKeys:[.fileSizeKey])
    let fileSize = resources.fileSize!
    print ("\(fileSize)")
} catch {
    print("Error: \(error)")
}
Upset Unicorn

Swift Obtenha o tamanho do arquivo do URL

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
    }
}
Ghaith Alzin

Respostas semelhantes a “Swift Obtenha o tamanho do arquivo do URL”

Perguntas semelhantes a “Swift Obtenha o tamanho do arquivo do URL”

Procure respostas de código populares por idioma

Procurar outros idiomas de código