Swift编译器错误 – 在发送'tableView'的SIL时

使用Xcode 6 Beta 5.我正在build立一个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 } 

这是编译错误:

 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 

这一行的问题

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

你有一个OrderHistoryDataModel数组的数组
当你从2个数组中获取对象时,Xcode无法理解对象的types – [indexPath.section][indexPath.row - 1]
修复它 – 以这种方式指定orderItemsArray中的对象的types

  var orderItemsArray: [[OrderHistoryDataModel]] = [] 

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

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

也清除你的项目并删除DerivedData文件夹。

如果Koval的答案没有解决它,看看你的class级是否有一个隐式的解包可选(!)布尔,你尝试使用它的三元操作。

在我的例子中,我在模型类中有这样的事情

 var isParent: Bool! 

和cellForRow(_)

 folder.isParent ? "xyz" : "abc" 

在我的情况下,这是一个简单的修复。 而不是让布尔隐式解包的属性,我只是默认分配给它为false。 无论如何,它正在初始化器中设置。

积分