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 Build a Simple iPhone App with Swift 2.0 Improving Our User Interface Finishing Up Our Layout

Michael Murray
Michael Murray
6,037 Points

Compile completes but simulator halts before anything displays.

I see that in the debugger that it halts in the first thread the breakpoint at 1.4

Michael Murray
Michael Murray
6,037 Points

My code:

// // FactModel.swift // FunFacts // // Created by Michael L. Murray on 6/16/16. // Copyright © 2016 Michael L. Murray. All rights reserved. //

import GameKit

struct FactModel { let facts = [ "Ants stretch when they wake up in the morning.", "Ostriches can run faster than horses.", "Olympic gold medals are actually made mostly of silver.", "You are born with 300 bones; by the time you are an adult you will have 206.", "It takes about 8 minutes for light from the Sun to reach Earth.", "Some bamboo plants can grow almost a meter in just one day.", "The state of Florida is bigger than England.", "Some penguins can leap 2-3 meters out of the water.", "On average, it takes 66 days to form a new habit.", "Mammoths still walked the Earth when the Great Pyramid was being built." ]

func getRandomFact() -> String {
    let randomNumber =
        GKRandomSource.sharedRandom().nextIntWithUpperBound(facts.count)

    /*  Class that we are getting Random Number from
    //  is GKRandomSource.  Usually we create an
    //  instance here but we are not.  Instead we are
    //  going to DIRECTLY CALL A METHOD ON IT.  We do
    //  this with calling sharedRandom.  This is a
    //  CLASS METHOD OR A TYPE METHOD.  In this case
    //  it returns an instance.
    //  Note the dot ".".  This is because we are
    //  CHAINING METHODS.  Next one nextIntWith . . .
    //  nextIntWithUpperBound(10)
    //  This method accepts an upper bounds input.
    //  We are setting it at 10.  A better way is to
    //  dynamically set it with the use of the count
    //  property of all array.
    */


    return facts[randomNumber]
}

}

// // ViewController.swift // FunFacts // // Created by Michael L. Murray on 5/21/16. // Copyright © 2016 Michael L. Murray. All rights reserved. //

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!

let factModel = FactModel()

override func viewDidLoad() {
    super.viewDidLoad()
    funFactLabel.text = factModel.getRandomFact()
}

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

@IBAction func showFunFact() {
    funFactLabel.text = factModel.getRandomFact()
}

}


// // AppDelegate.swift // FunFacts // // Created by Michael L. Murray on 5/21/16. // Copyright © 2016 Michael L. Murray. All rights reserved. //

import UIKit

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    return true
}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

Michael Murray
Michael Murray
6,037 Points

It was running fine until I started putting in the constraints on the label. I tried taking out the restraints. No better. Please Help. I would like to move on, but I need to know what happened so that I can avoid the problem in the future.

2 Answers

Michael Murray
Michael Murray
6,037 Points

Never found an answer to this problem. I started a new project and worked through the entire lesson again and everything worked fine with it. ????????