Xcode 挂在“编译 Swift 源文件”上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38174514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode hangs on "Compiling Swift source files"
提问by Steve Kuo
I'm running Xcode 7.3.1. When building my Swift based project, it hangs on "Compiling Swift source files". I've tried various combination of deleting DerivedData
, clean, run, restarting Xcode, restarting OS X, none seem to work. Any ideas?
我正在运行 Xcode 7.3.1。在构建我的基于 Swift 的项目时,它挂在“编译 Swift 源文件”上。我尝试了删除DerivedData
、清理、运行、重新启动 Xcode、重新启动 OS X 的各种组合,但似乎都不起作用。有任何想法吗?
采纳答案by Steve Kuo
Thanks for all commentors' suggestions. I narrowed it down to a map
's closure referencing a property that I had removed. Example:
感谢所有评论者的建议。我将它缩小到 amap
的闭包引用我已删除的属性。例子:
var people: [Person] = ...
let foo = people.map { "\(protocol Person {
var name: String { get }
var age: Int { get }
}
.name), \(class X: X
.age)" }
where Person
looks something like:
哪里Person
看起来像:
json = [ "item1": value1 ?? "",
"item2": value2 ?? "",
"item3": value3 ?? "",
...
"item14": value14 ?? "" ]
This all works fine. Then I removed age
while keeping the closure unchanged. This caused Xcode to become hopelessly confused. Probably related to the Swift's type inference.
这一切正常。然后我age
在保持关闭不变的情况下移除。这导致 Xcode 变得无可救药地困惑。可能与 Swift 的类型推断有关。
回答by Hai
I made a class extend itself. That also causes Swift compiler to get stuck in a loop without error:
我做了一个类扩展自己。这也会导致 Swift 编译器在没有错误的情况下陷入循环:
json = [ "item1": value 1,
"item2": value 2,
"item3": value 3,
...
"item14": value 14 ]
回答by UKDataGeek
Try clean your Project Build Folder
尝试清理您的项目构建文件夹
- Hold down option key and got to Product -> Clean Build Folder ( where Clean used to be in the menu)
- If you are using CocoaPods delete your Workspace file and run
Pod Install
orPod Update
- 按住 option 键并进入 Product -> Clean Build Folder(其中 Clean 曾经在菜单中)
- 如果您使用 CocoaPods,请删除您的 Workspace 文件并运行
Pod Install
或Pod Update
I think 2 is probably the cause.
我认为2可能是原因。
回答by Miroslav Ku?ák
Change "Swift Compiler Optimization Level" in Build Settings from "Whole module optimization" to "Single file optimization". It may not be your problem, but it solved mine I was stuck with for half a day. It may just be a temporary bug in the recent Xcode version (8.2.1 was the one I have been using at the time I wrote this).
将 Build Settings 中的“Swift Compiler Optimization Level”从“Whole module optimization”更改为“Single file optimization”。这可能不是你的问题,但它解决了我被困半天的问题。这可能只是最近 Xcode 版本中的一个临时错误(8.2.1 是我在编写本文时一直在使用的版本)。
回答by Jeff Evernham
I had the same problem. In my case it seems to be a result of applying too many nil coalescing actions. I was building a json item:
我有同样的问题。在我的情况下,这似乎是应用太多 nil 合并操作的结果。我正在构建一个 json 项目:
requestParameters = [
"asset" : "...",
"user" : "...",
// about 15 additional keys
]
This wouldn't compile. When I removed all the nil coalescing so that it looked like the following, it compiled fine.
这不会编译。当我删除所有 nil 合并使其看起来如下所示时,它编译得很好。
var requestParameters = [String : Any]()
requestParameters["asset"] = "..."
requestParameters["user"] = "..."
// about 15 additional keys
I did not try to figure out the cutoff point for the number of items before it got stuck.
在它卡住之前,我没有试图找出项目数量的截止点。
回答by denkeni
There seems to be various possible causes of extremely long compilation time. Corner or edge cases are everywhere. So the best way is to observe and investigate your own case.
编译时间过长似乎有多种可能的原因。角落或边缘情况无处不在。所以最好的方法是观察和调查你自己的情况。
Although being mentioned by others in comments, but steps below still worths more attention:
虽然在评论中被其他人提及,但以下步骤仍然值得更多关注:
- Run project
- Switch to Report Navigator(command + 9), and select current running
Build
task. See which source file is taking up a lot of compiling time. - Check recent commit history of that source file. Investigate the possible cause.
- 运行项目
- 切换到Report Navigator(command + 9),然后选择当前正在运行的
Build
任务。查看哪个源文件占用了大量编译时间。 - 检查该源文件的最近提交历史记录。调查可能的原因。
回答by Swati Gupta
In my case the problem was during JSON parsing. I was sending an optional value in a dictionary parameter during JSON parsing.
就我而言,问题出在 JSON 解析过程中。在 JSON 解析期间,我在字典参数中发送了一个可选值。
回答by Tamás Sengel
Watching the Report Navigator helped me find the problem. In my case, the issue was that I tried to add auto layout constraints to a programmatically added subview of a UITableView
in a UITableViewController
.
观看报告导航器帮助我找到了问题。在我的情况下,问题是,我试图自动布局约束增加的一个编程方式添加子视图UITableView
中UITableViewController
。
回答by Serhiy
In my case XCode stucks on big dictionary literal:
在我的情况下,XCode 停留在大字典文字上:
##代码##The problem was fixed after replacing this part by:
更换此部件后问题已解决:
##代码##回答by Werner Kratochwil
xcode seems to have a problem concatenating more than 5 strings. See this: Xcode freezes when trying to execute this in a Swift playground?The given workaround solved my problem
xcode 似乎在连接 5 个以上的字符串时有问题。看到这个: Xcode 在 Swift 的操场中尝试执行时冻结?给定的解决方法解决了我的问题