Xcode挂起"编译Swift源文件"

时间:2016-07-03 21:31:02

标签: ios xcode swift xcode7

我正在运行Xcode 7.3.1。在构建基于Swift的项目时,它依赖于"编译Swift源文件"。我已经尝试了删除{{1}},清理,运行,重新启动Xcode,重新启动OS X的各种组合,似乎都没有工作。有什么想法吗?

13 个答案:

答案 0 :(得分:15)

我做了一个类扩展自己。这也导致Swift编译器陷入循环而没有错误:

class X: X

答案 1 :(得分:7)

感谢所有评论员的建议。我把它缩小到map的闭包,引用了我删除的属性。例如:

var people: [Person] = ...
let foo = people.map { "\($0.name), \($0.age)" }

其中Person类似于:

protocol Person {
    var name: String { get }
    var age: Int { get }
}

一切正常。然后我删除age,同时保持闭包不变。这导致Xcode变得无可救药地混淆。可能与Swift的类型推断有关。

答案 2 :(得分:6)

尝试清理项目构建文件夹

  1. 按住选项键并进入产品 - >清洁构建文件夹(清除以前在菜单中)
  2. 如果您使用的是CocoaPods,请删除您的工作区文件并运行Pod InstallPod Update
  3. 我认为2可能是原因。

答案 3 :(得分:5)

更改" Swift编译器优化级别"来自"整个模块优化"的构建设置到"单个文件优化"。这可能不是你的问题,但它解决了我的问题,我被困了半天。它可能只是最近Xcode版本中的一个临时错误(8.2.1是我在撰写本文时使用的那个)。

答案 4 :(得分:4)

我遇到了同样的问题。在我的情况下,它似乎是应用太多零合并操作的结果。我正在建立一个json项目:

json = [ "item1": value1 ?? "",
         "item2": value2 ?? "",
         "item3": value3 ?? "",
         ...
         "item14": value14 ?? "" ]

这不会编译。当我删除所有nil合并使它看起来像下面这样,它编译得很好。

json = [ "item1": value 1,
         "item2": value 2,
         "item3": value 3,
         ...
         "item14": value 14 ]

我没有试图弄清楚卡住之前物品数量的截止点。

答案 5 :(得分:3)

似乎有多种可能的原因导致编译时间过长。角落或边缘情况无处不在。因此,最好的方法是观察和调查自己的情况。

尽管在评论中被其他人提及,但是下面的步骤仍然值得更多关注:

  1. 运行项目
  2. 切换到 Report Navigator (命令+ 9),然后选择当前正在运行的Build任务。查看哪个源文件占用大量编译时间。
  3. 检查该源文件的最近提交历史记录。调查可能的原因。

答案 6 :(得分:2)

在我的情况下,问题出在JSON解析期间。我在JSON解析期间在字典参数中发送了一个可选值。

答案 7 :(得分:1)

观看Report Navigator帮助我找到问题所在。就我而言,问题在于我尝试将自动布局约束添加到UITableViewUITableViewController的编程添加子视图中。

答案 8 :(得分:1)

我发现有用的是RoystonP在https://forums.developer.apple.com/thread/115303上发布的帖子:

1. Open Activity Monitor.
2. Start your project building.
3. Wait for the the build’s progress to completely stop for several minutes.
4. Locate the Swift processes in Activity Monitor (they should be using nearly 100% CPU) and select one of them.
5. In the menu bar, select “View”, then “Send Signal To Process…”
6. Select “Abort (SIGABRT)” from the drop-down list.
7. Click the “Send” button. This will simulate an assertion failing, so the compiler will print information about what it’s doing and then exit.
8. In Xcode, switch to the Report Navigator (the “speech bubble” button over the left-side pane) and select the build.
9. Scroll down to the now-failed compilation step and click the transcript button (button with five lines, to the right of the “Compile [Filename]” line).
10. Scroll down to see the diagnostic information. It will probably include a list of command-line flags, a few lines saying things like “In pass SimplifyCFG”, and a stack trace.


您可能必须重复步骤6和7才能使其正常工作。

答案 9 :(得分:0)

xcode似乎连接超过5个字符串有问题。 看到这个: Xcode freezes when trying to execute this in a Swift playground? 给定的解决方法解决了我的问题

答案 10 :(得分:0)

在我的情况下,XCode卡在大字典文字上:

requestParameters = [
                        "asset" : "...",
                        "user" : "...",
                        // about 15 additional keys
                        ]

通过以下方式更换此部件后问题得以解决:

var requestParameters = [String : Any]()
requestParameters["asset"] = "..."
requestParameters["user"] = "..."
// about 15 additional keys

答案 11 :(得分:0)

因此,我认为在大多数情况下,这是众所周知的字典文字类型干扰问题。

这样的代码:

 let params = [
                "title": title, "desc": desc, "velikost": velikost,
                "cena": cena, "vykon": vykon, "telefon": telefon,
                "rokVyroby": rokVyroby, "stkDo": stkDo,
                "zemePuvodu": zemePuvodu, "najetoKilometru": najetoKilometru,
                "stav": stav, "ZnackaId": znackaId,
                "VyrobceId": vyrobceId,
                "category": categoryId, "subCategory": subCategoryId,
                "modely[]": modelId, "prodejNakup": prodejNakup,
                "mena": mena, "isNovy": isNovy, "serviska": serviska,
                "abs": abs, "technicak": technicak,
            ]

必须始终像这样写得更好:

let params: [String: String] = [
                "title": title, "desc": desc, "velikost": velikost,
                "cena": cena, "vykon": vykon, "telefon": telefon,
                "rokVyroby": rokVyroby, "stkDo": stkDo,
                "zemePuvodu": zemePuvodu, "najetoKilometru": najetoKilometru,
                "stav": stav, "ZnackaId": znackaId,
                "VyrobceId": vyrobceId,
                "category": categoryId, "subCategory": subCategoryId,
                "modely[]": modelId, "prodejNakup": prodejNakup,
                "mena": mena, "isNovy": isNovy, "serviska": serviska,
                "abs": abs, "technicak": technicak,
            ]

但是我认为,更短的文字会成为问题,并且可以通过等待构建来节省时间,最好总是为字典文字定义类型,这样编译器就不必自己去发现,因为他显然很费力。 PS:我认为苹果工程师在那里存在一些严重的个人问题,他们必须从Jatbrains甚至我这里雇用一些人;)专注于重要的事情,而不是浪费时间讨论Swift与他人之间的区别...

答案 12 :(得分:0)

我遇到的错误是The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

我在这里错过了向左箭头。

enter image description here

相关问题