Xcode 8 very slow Swift compiling

后端 未结 8 1499
太阳男子
太阳男子 2020-12-12 13:54

Ever since Swift 3 and Xcode 8 my project compiles quite slowly. Every time I add so much as an empty line to a file, recompiling takes a full minute. When I check the outpu

8条回答
  •  孤城傲影
    2020-12-12 14:21

    One common practice that slows down compile time is using Array.append and String.append (or their + operator equivalents). For Strings, it's better to use a formatted string, so instead of

    let hello = "Hello, "
    let world = "World!"
    let combinedString = hello + world
    

    you should use

    let combinedString = "\(hello)\(world)"
    

    I can't remember the exact speedup, but it was on the order of 10 times for those particular lines. Odds are, thought, that this won't have a noticeable speedup for any but the tinest projects. For example, our project has hundreds of Swift files, as well as many Objective-C ones, and our compile times are often 10 minutes or more, sometimes even when the only change was to a non-Swift file.

提交回复
热议问题