Swift编译器错误 - 为' tableView'发出SIL在

时间:2014-08-13 04:45:22

标签: ios xcode uitableview swift

使用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
}

这是编译错误:

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

1 个答案:

答案 0 :(得分:15)

此行中的问题

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

你有一个 OrderHistoryDataModel 的阵列数组 当你从2个数组中获取对象时,Xcode无法理解对象的类型 - [indexPath.section][indexPath.row - 1] 修复它 - 在orderItemsArray中指定对象的类型

  var orderItemsArray: [[OrderHistoryDataModel]] = [] 

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

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

同时清除项目并删除DerivedData文件夹。