【问题标题】:Reading Bundle.main.path at the launching of the app is time consuming or not?在应用程序启动时读取 Bundle.main.path 是否耗时?
【发布时间】:2021-05-11 17:13:02
【问题描述】:

对于特定于应用程序,我有与环境和配置相关的 json 文件,在应用程序启动时读取这些文件是否耗时? (当然我在启动时需要它)如果是的话,我将使用脚本创建结构常量

Bundle.main.path(forResource: ConfigPath.urlString(api: .environment), ofType: "json")

【问题讨论】:

    标签: ios objective-c swift xcode swift3


    【解决方案1】:

    读取或写入文件是最耗时的操作之一。无论您是否在应用程序启动时执行此操作。如果您想检查它如何影响启动时间,您可以创建一个简单的 UI 测试并在有和没有文件操作的情况下运行它。

    import XCTest
    
    class UILaunchTests: XCTestCase {
      func testLaunchPerformance() {
        if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {
          measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) {
            XCUIApplication().launch()
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 2023-03-06
      • 2016-08-05
      • 2014-05-06
      相关资源
      最近更新 更多