I think something like this should work:
do {
let fileAttributes = try FileManager.default().attributesOfItem(atPath: file.path!)
if let fileSizeNumber = fileAttributes["NSFileSize"] as? NSNumber {
let fileSize = fileSizeNumber.int64Value
}
} catch let error as NSError {
print("Filesize reading failed: \(error.debugDescription)")
}
NSFileSize , . , , , ( , , ).
Xcode 8 GM:
FileAttributeKey.size , ( @rudy ). :
do {
let attributes = try FileManager.default.attributesOfItem(atPath: file.path)
if let size = attributes[FileAttributeKey.size] as? NSNumber {
let fileSize = size.int64Value
print(fileSize)
}
} catch {
print(error.localizedDescription)
}