Swift compiler error - when issuing SIL for 'tableView' in
Using Xcode 6 Beta 5. I am creating a tableviewcontroller and these few lines of code will not 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
}
Here's a compilation 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
source to share
The problem is this line
var orderHistoryDataModel: OrderHistoryDataModel = self.orderItemsArray[indexPath.section][indexPath.row - 1] as OrderHistoryDataModel
You have an array of arraysOrderHistoryDataModel
.
Xcode can't figure out the type of object when you get an object from 2 arrays at that time - [indexPath.section][indexPath.row - 1]
.
Fix - specify the type of objects in orderItemsArray
like this
var orderItemsArray: [[OrderHistoryDataModel]] = []
You can also try to get the 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]
Also clean the project and delete the DerivedData folder.
source to share
if Koval's answer doesn't fix it, see if your class has a bool implicitly unwrapped optionally (!) and you're trying to use ternary operation on it.
in my case i had something like this in my model class
var isParent: Bool!
and in cellForRow (_)
folder.isParent ? "xyz" : "abc"
In my case, it was a simple solution. instead of bool implicitly expanding the property, I just assign it false by default. Either way, it got set in the initializer anyway.
source to share