我已经为这个项目工作了2个月,但是因为Xcode卡在“索引”上而突然停止工作。我无法再构建该项目。如果我尝试构建,Xcode会冻结,我必须强制退出。这只发生在这个项目中。
我尝试清除所有派生数据,但没有帮助。
我正在使用Xcode 4.5.2。
有任何想法吗?
我已经为这个项目工作了2个月,但是因为Xcode卡在“索引”上而突然停止工作。我无法再构建该项目。如果我尝试构建,Xcode会冻结,我必须强制退出。这只发生在这个项目中。
我尝试清除所有派生数据,但没有帮助。
我正在使用Xcode 4.5.2。
有任何想法吗?
我在 Swift 2.2 中遇到了同样的问题。
这与一个泛型函数重载有关。
func warnLog() {
print("Warning line: \(#line) file: \(#file) ")
}
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
func warnLog<T>(input:T) -> T {
print("Warning line: \(#line) file: \(#file) ")
return input
}
我所需要做的就是移除一个未使用的过载函数。
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
我知道这是一个相当旧的问题,但是问题仍然存在。以下是我发现的经验。
在NavigationLink内部,我给了一个没有接受参数的View一个参数。它挂起构建和索引,但没有触发编译器错误。那不太好。
以下是我如何重现它。在包含导航视图的顶级视图中,我在堆栈中的列表内使用了以下块。因此,我的顶级视图层次结构类似于(伪代码):
Body {
VStack {
[CustomViewForPageHeader]
List {
(the code block pasted below)
(some other things)
}
}
}
问题出在这里:
if 0 < viewModel.taskUpdates.count {
Section( "Chore updates"){
ForEach(viewModel.taskUpdates, id:\.id){ update in
if "complete" == update.statusType {
NavigationLink {
CompletedTaskApprovalView( update: update )
} label: {
Text(update.formattedMessage)
.padding(.vertical)
}
}
if "reject" == update.statusType {
Text(update.formattedMessage)
.padding(.vertical)
}
}
}
}
我记得在重构一些数据时删除了参数,但编译器并没有因此而出错,这让我感到沮丧。于是我注释掉了整行代码,使其看起来像这样:
if 0 < viewModel.taskUpdates.count {
Section( "Chore updates"){
ForEach(viewModel.taskUpdates, id:\.id){ update in
if "complete" == update.statusType {
NavigationLink {
//CompletedTaskApprovalView( update: update )
} label: {
Text(update.formattedMessage)
.padding(.vertical)
}
}
if "reject" == update.statusType {
Text(update.formattedMessage)
.padding(.vertical)
}
}
}
}
然后,它出奇迹般地正常工作了。
取消注释并删除参数...
if 0 < viewModel.taskUpdates.count {
Section( "Chore updates"){
ForEach(viewModel.taskUpdates, id:\.id){ update in
if "complete" == update.statusType {
NavigationLink {
CompletedTaskApprovalView()
} label: {
Text(update.formattedMessage)
.padding(.vertical)
}
}
if "reject" == update.statusType {
Text(update.formattedMessage)
.padding(.vertical)
}
}
}
}
struct CompletedTaskApprovalView: View {
var body: some View {
Text("Approve chores")
.font(.title)
}
}
struct SomeTestView: View {
var body: some View {
Text("this is just a thing")
}
}
并将其添加到我的循环中...
if 0 < viewModel.taskUpdates.count {
Section( "Chore updates"){
ForEach(viewModel.taskUpdates, id:\.id){ update in
if "complete" == update.statusType {
NavigationLink {
//CompletedTaskApprovalView()
SomeTestView()
} label: {
Text(update.formattedMessage)
.padding(.vertical)
}
}
if "reject" == update.statusType {
Text(update.formattedMessage)
.padding(.vertical)
}
}
}
}
运行正常。
在上面的实例化中添加了一个参数(但没有在视图的结构定义中添加参数)...... 它的行为与原始问题相同-挂起了构建和索引,似乎无休止地,并且从未出现我预期的参数错误。
if 0 < viewModel.taskUpdates.count {
Section( "Chore updates"){
ForEach(viewModel.taskUpdates, id:\.id){ update in
if "complete" == update.statusType {
NavigationLink {
//CompletedTaskApprovalView()
SomeTestView( fish: "sandwich" )
} label: {
Text(update.formattedMessage)
.padding(.vertical)
}
}
if "reject" == update.statusType {
Text(update.formattedMessage)
.padding(.vertical)
}
}
}
}
这太离奇了,让人百分之百的失望。我不想再深入诊断它了,但是...如果还有人遇到这种情况,请尝试一下;仔细检查您的参数和声明,也许您会发现类似的问题。
奇怪。令人沮丧。困惑。烦人。
@EnvironmentObject var roomViewModel
我需要的地方:
@EnvironmentObject var roomViewModel: RoomViewModel
没有编译器错误,只是无尽的索引。当我修复了错误后,项目很快就构建完成了。
我尝试了所有列出的方法,但索引仍然冻结。这个方法帮助了我:如果你的索引被冻结,并且有一个或多个Swift进程占用了你99%的CPU - 只需杀死这些Swift任务,等待一会儿,进度就会继续。这可能需要重复多次,直到完成为止,在我的情况下,我杀死了7次进程,但最终,索引已经完成!
如果您的Xcode上还有其他应用程序在运行,请先停止它,然后再停止正在运行的应用程序。这样您就可以继续进行索引。
这对我有效