xcode Swift 编译器错误 - 在为“tableView”发出 SIL 时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25278233/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:22:47  来源:igfitidea点击:

Swift compiler error - While emitting SIL for 'tableView' at

iosxcodeuitableviewswift

提问by Renu

Using Xcode 6 Beta 5. I am building a tableviewcontroller and these few lines of code won't compile.

使用 Xcode 6 Beta 5。我正在构建一个 tableviewcontroller,这几行代码将无法编译。

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! 
{
    let cell : OrderHistoryCell = tableView.dequeueReusableCellWithIdentifier("CellForOrderHistory", forIndexPath: indexPath) as OrderHistoryCell

    var orderHistoryDataModel: OrderHistoryDataModel = self.orderItemsArray[indexPath.section][indexPath.row - 1] as OrderHistoryDataModel

    cell.nameLabel.text = orderHistoryDataModel.orderItem.title
    cell.statusLabel.text = orderHistoryDataModel.shipment.shippingStatus.toRaw()

    let imageData: NSData = NSData(contentsOfURL: orderHistoryDataModel.orderItem.imageURL)
    cell.thumbnailImageView.image = UIImage(data: imageData)

    return cell
}

Here's the compile error:

这是编译错误:

CompileSwift normal x86_64 com.apple.xcode.tools.swift.compiler
     ........ ............

 Stack dump: ....... ........
 intermediates/newProject.build/Debug-iphonesimulator/newProject.build/Objects-
 normal/x86_64/OrderHistoryViewController.o

 1. While emitting SIL for 'tableView' at /Users/testuser/Downloads/newProject/newProject/OrderHistoryViewController.swift:131:5
 <unknown>:0: error: unable to execute command: Segmentation fault: 11
 <unknown>:0: error: swift frontend command failed due to signal 
 (use -v to see invocation) Command /Applications/Xcode6-Beta5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
 failed with exit code 254

回答by Kostiantyn Koval

The problem in this line

这一行的问题

   var orderHistoryDataModel: OrderHistoryDataModel = self.orderItemsArray[indexPath.section][indexPath.row - 1] as OrderHistoryDataModel

You have an Array of Arrays of OrderHistoryDataModel.
Xcode can't understand type of the object when you get object from 2 arrays at the time - [indexPath.section][indexPath.row - 1].
To fix it - Specify the type of the objects inorderItemsArraylike this

您有一个Arrays of ArraysOrderHistoryDataModel
当您当时从 2 个数组中获取对象时,Xcode 无法理解对象的类型 - [indexPath.section][indexPath.row - 1]
修复它 -orderItemsArray像这样 指定对象的类型

  var orderItemsArray: [[OrderHistoryDataModel]] = [] 

You can also try to get object in 2 steps. Change this code [indexPath.section][indexPath.row - 1]to this:

您也可以尝试分两步获取对象。将此代码更改[indexPath.section][indexPath.row - 1]为:

var models: [OrderHistoryDataModel] = self.orderItemsArray[indexPath.section]
var orderHistoryDataModel: OrderHistoryDataModel =  models[indexPath.row - 1]

Also clear your project and delete DerivedData folder.

还要清除您的项目并删除 DerivedData 文件夹。

回答by newDeveloper

if Koval's answer didn't fix it, see if your class has a bool that's an implicitly unwrapped optional (!) and you try to use a ternary operation on it.

如果 Koval 的回答没有解决它,请查看您的类是否有一个隐式展开的可选 (!) 的 bool,然后您尝试对其使用三元运算。

in my case I had something like this in my model class

就我而言,我的模型类中有这样的东西

var isParent: Bool!

and in cellForRow(_)

并在 cellForRow(_)

folder.isParent ? "xyz" : "abc"

In my case it was an easy fix. instead of making the bool an implicitly unwrapped property I just assign it to false by default. It was getting set in the initializer anyway.

在我的情况下,这是一个简单的修复。我没有将 bool 设置为隐式展开的属性,而是默认将其分配给 false。无论如何,它是在初始化程序中设置的。

Credits

学分