5

Thoroughly searched for this question but was not able to find it in Stack Overflow.

Getting segmentation fault error:

1.  While type-checking getter for asset at <invalid loc>

Below is the code of the class for which I am getting Segmentation Fault -

import UIKit

class WidgetImageTableViewCell: UITableViewCell {

    @IBOutlet weak var imgViewWidget: UIImageView!

    var aspectConstraint : NSLayoutConstraint!
 {
        didSet {
            if oldValue != nil {
                imgViewWidget.removeConstraint(oldValue!)
            }

            if aspectConstraint != nil {
                imgViewWidget.addConstraint(aspectConstraint!)
            }
        }
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        aspectConstraint = nil
    }

    func setPostedImage(image : UIImage) {

        let aspect:CGFloat = image.size.width/image.size.height
        aspectConstraint = NSLayoutConstraint(item: imgViewWidget, attribute: .width, relatedBy: .equal, toItem: imgViewWidget, attribute: .height, multiplier: aspect, constant: 0.0)

        imgViewWidget.image = image

    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {

        super.setSelected(selected, animated: animated)
    }


}

Also, below is the screenshot of the stacktrace that I am getting while building - Stack trace image

Kunal Das
  • 51
  • 2
  • 1
    Segmentation faults in `Swift` usually mean there is a compiler bug. Have a look at [this](https://stackoverflow.com/questions/24222644/swift-compiler-segmentation-fault-when-building) post, there are useful workarounds in the answers. – Dávid Pásztor Aug 09 '17 at 09:03
  • Sometimes I get segmentation fault when something is missing: eg. something in the storyboard or a link outlet-code, etc. –  Aug 09 '17 at 09:25
  • Adding your whole code into a brand-new Single View App project, no Segmentation Fault occurred. (Tested on Xcode 8.3.3.) You may need to find what other parts of your project is affecting. – OOPer Aug 09 '17 at 11:14
  • 1
    Thanks for the help everyone, the issue was with the Xcode 8.0 compiler as soon as I updated the Xcode to latest version, the issue was vanished. – Kunal Das Aug 22 '17 at 09:55

0 Answers0