Calculate size of iOS framework using Swift script

雨燕双飞 提交于 2020-01-06 07:01:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!