问题
I have a Swift script I'm writing to calculate the file size of an iOS framework. However, I have weird results. In one framework I have this file structure as shown in the Finder:
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/x86_64.swiftmodule
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/x86_64.swiftdoc
HOWEVER! If I run code to calculate file size in my Swift script, as I'm looping through the files I see these files:
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/arm64.swiftmodule
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/arm.swiftmodule
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/arm64.swiftdoc
/{FrameworkName}.framework/Modules/{FrameworkName}.swiftmodule/arm.swiftdoc
As you can see, the files seem to split into 2 different files per architecture that is not shown in the Finder. The problem here is that both of those arm
and arm64
files are counted with the same size, therefore double counting my file size for the iOS Framework!
Right now I'm thinking this may be a bug in how Swift is looping through the file structure, but maybe I'm doing something wrong.
Here's my file size calculation code:
var bool: ObjCBool = false
if FileManager.default.fileExists(atPath: documentsDirectoryURL.path, isDirectory: &bool), bool.boolValue {
var folderSize = 0
FileManager.default.enumerator(at: documentsDirectoryURL, includingPropertiesForKeys: [.<key_here>], options: [])?.forEach {
folderSize += (try? ($0 as? URL)?.resourceValues(forKeys: [.<key_here>]))??.<key_here> ?? 0
}
return Int64(folderSize)
}
来源:https://stackoverflow.com/questions/47624237/calculate-size-of-ios-framework-using-swift-script