问题描述
使用 Xcode 6 Beta 5.我正在构建一个 tableviewcontroller,这几行代码将无法编译.
Using Xcode 6 Beta 5.I am building a tableviewcontroller and these few lines of code won't compile.
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 无法理解对象的类型 - [indexPath.section][indexPath.row - 1]
.
修复它 - 在 orderItemsArray
中指定对象的类型
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 inorderItemsArray
like this
var orderItemsArray: [[OrderHistoryDataModel]] = []
您也可以尝试分两步获取对象.将此代码 [indexPath.section][indexPath.row - 1]
更改为:
You can also try to get object in 2 steps. Change this code [indexPath.section][indexPath.row - 1]
to this:
var models: [OrderHistoryDataModel] = self.orderItemsArray[indexPath.section]
var orderHistoryDataModel: OrderHistoryDataModel = models[indexPath.row - 1]
同时清除您的项目并删除 DerivedData 文件夹.
Also clear your project and delete DerivedData folder.
这篇关于Swift 编译器错误 - 在为“tableView"发出 SIL 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!