Xcode 8.1 swift 3 take forever to compile this code

后端 未结 3 899
萌比男神i
萌比男神i 2021-01-24 05:01

I have this class in a project which previously use swift 2.3. When i migrated the project to swift 3, xcode took forever to compile and i saw it stuck at this class. I can not

3条回答
  •  礼貌的吻别
    2021-01-24 05:21

    If you're not doing so already adding a -Xfrontend -debug-time-function-bodies compiler flag to your project will list the time required to compile each function. That can be a useful way to identify what exactly is slow in your build. (See http://irace.me/swift-profiling or https://thatthinginswift.com/debug-long-compile-times-swift/).

    In your case the compiler is probably struggling to determine the type of your dictionary literal. Looking at each key and value and then trying to find the most appropriate common type for all of them. If you specified a type then I expect the compiler will only need to verify that your literal matches that type and compile much more quickly:

    let result: [String: Any] = ["id": id, ...]
    return result
    

提交回复
热议问题