Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Auto Layout in iOS Auto Layout in Code Blues and Purples

Patrick McLeod
Patrick McLeod
5,913 Points

Build successful but simulator screen stays blank & Thread 1: signal SIGABRT

I'm stuck on Blues and Purples. I have the code exactly the same (I think) but then I try and run the Simulator, I get the prompt that the says "Build Successful" but the screen on the simulator stays blank.

I also get thrown back to the DeBug Navigator on Xcode and get a message that says Thread 1: signal SIGABRT beside the following code: class AppDelegate: UIResponder, UIApplicationDelegate {

My code is as follows

//
//  ViewController.swift
//  AutoLayoutExample5
//
//  Created by patrickmcleod on 2/15/18.
//  Copyright © 2018 Rebel Holdings Corp. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    let orangeView = UIView()
    let purpleView = UIView()
    let blueView = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        orangeView.backgroundColor = UIColor(red: 255/255.0, green: 148/255.0, blue: 0/255.0, alpha: 1.0)
        view.addSubview(orangeView)

        purpleView.backgroundColor = UIColor(red: 204/255.0, green: 102/255.0, blue: 255/255.0, alpha: 1.0)
        view.addSubview(purpleView)

        blueView.backgroundColor = UIColor(red: 102/255.0, green: 204/255.0, blue: 255/255.0, alpha: 1.0)
        view.addSubview(blueView)
    }

    override func viewWillLayoutSubviews() {
        setupOrangeViewConstraints()
        setupPurpleViewConstraints()
        setupBlueViewConstraints()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

   func setupOrangeViewConstraints() {
        orangeView.translatesAutoresizingMaskIntoConstraints = false

        let orangeViewCenterXConstraint = NSLayoutConstraint(item: orangeView, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0.0)
        let orangeViewBottomConstraint = NSLayoutConstraint(item: orangeView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottomMargin, multiplier: 1.0, constant: -50.0)
        let orangeViewHeightXConstraint = NSLayoutConstraint(item: orangeView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 57.0)
        let orangeViewWidthConstraint = NSLayoutConstraint(item: orangeView, attribute: .width, relatedBy: .equal, toItem: view, attribute: .notAnAttribute, multiplier: 1.0, constant: 200.0)

        view.addConstraints([
            orangeViewWidthConstraint, orangeViewBottomConstraint, orangeViewCenterXConstraint, orangeViewHeightXConstraint])
    }

    func setupPurpleViewConstraints() {
        purpleView.translatesAutoresizingMaskIntoConstraints = false

        let purpleViewLeadingSpaceConstraint = NSLayoutConstraint(item: purpleView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leadingMargin, multiplier: 1.0, constant: 8.0)
        let purpleViewBottomSpaceConstraint = NSLayoutConstraint(item: purpleView, attribute: .bottom, relatedBy: .equal, toItem: orangeView, attribute: .topMargin, multiplier: 1.0, constant: -8.0)
        let purpleViewTrailingSpaceConstraint = NSLayoutConstraint(item: purpleView, attribute: .trailing, relatedBy: .equal, toItem: blueView, attribute: .leadingMargin, multiplier: 1.0, constant: -8.0)
        let purpleViewTopSpaceConstraint = NSLayoutConstraint(item: purpleView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .topMargin, multiplier: 1.0, constant: 8.0)

        view.addConstraints([
            purpleViewTopSpaceConstraint, purpleViewBottomSpaceConstraint, purpleViewLeadingSpaceConstraint, purpleViewTrailingSpaceConstraint])
    }

   func setupBlueViewConstraints() {
        blueView.translatesAutoresizingMaskIntoConstraints = false

        let blueViewTopSpaceConstraint = NSLayoutConstraint(item: blueView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .topMargin, multiplier: 1.0, constant: 8.0)
        let blueViewBottomSpaceConstraint = NSLayoutConstraint(item: blueView, attribute: .bottom, relatedBy: .equal, toItem: orangeView, attribute: .topMargin, multiplier: 1.0, constant: -8.0)
        let blueViewTrailingSpaceConstraint = NSLayoutConstraint(item: blueView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailingMargin, multiplier: 1.0, constant: -8.0)
        let equalWidthConstraint = NSLayoutConstraint(item: blueView, attribute: .width, relatedBy: .equal, toItem: purpleView, attribute: .width, multiplier: 1.0, constant: 0.0)

        view.addConstraints([
            blueViewTopSpaceConstraint, blueViewBottomSpaceConstraint, blueViewTrailingSpaceConstraint, equalWidthConstraint])
    }

} 

1 Answer

Hi Patrick,

That error is usually caused by having a dead link between your code and your storyboard. Check you haven't deleted a UI element but left the link in place.

Steve.