Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}

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
like image 899
Renu Avatar asked Aug 13 '14 04:08

Renu


2 Answers

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 inorderItemsArray like this

  var orderItemsArray: [[OrderHistoryDataModel]] = [] 

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]

Also clear your project and delete DerivedData folder.

like image 104
Kostiantyn Koval Avatar answered Nov 10 '22 00:11

Kostiantyn Koval


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.

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 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.

Credits

like image 21
newDeveloper Avatar answered Nov 10 '22 00:11

newDeveloper