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

Fun Facts App Goes Black in Simulator - Adding a Pop of Color

I haven't had any issues with the Fun Facts App in the Swift track, but while completing a pop of color, I have run into an issue.

When running the app in the simulator, the interface briefly displays (less than a second) in black print and white background then goes completely black.

For the last day I've been backtracking and analyzing the instructor's code to find differences with mine. I've changed things around and undone them and still have them same issue. Does anyone know what may account for this? Is it possible I did something wrong with Ctrl dragging or in the inspectors?

I'd include my code, but I don't see anywhere to attach it

Edit:

Hi Luke,

Thanks for helping out. The link to the markdown cheat sheet appears to be refreshing the page, but I googled it. Titles are the top were put in by me to save room vs the actual header

Here's everything:

//View Controller
import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var funFactLabel: UILabel!
    @IBOutlet weak var funFactButton: UIButton!

    let factBook = FactBook()
    //initializing a new instance of the strut from FaceBook.swift
    let colorWheel = ColorWheel()


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

    }

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

// IBAction tells xCode it's linked to something in Interface Builder
    @IBAction func showFunFact() {
        var randomColor = colorWheel.randomColor()
        view.backgroundColor = randomColor
        funFactButton.tintColor = randomColor
        funFactLabel.text = factBook.randomFact()
    }

}
//FactBook
import Foundation


struct FactBook {
    let factsArray = [  "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 randomFact() -> String{

        var unsignedArrayCount = UInt32(factsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomNumber = Int(unsignedRandomNumber)

        return factsArray[randomNumber]

    }

}
//ColorWheel
import Foundation
import UIKit

struct ColorWheel{


    let colorsArray = [
        UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), //teal color
        UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), //yellow color
        UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), //red color
        UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), //orange color
        UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), //dark color
        UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), //purple color
        UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), //green color
    ]

    func randomColor() -> UIColor{
        var unsignedArrayCount = UInt32(colorsArray.count)
        var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        var randomNumber = Int(unsignedRandomNumber)

        return colorsArray[randomNumber]
    }
}
//Appdelegate
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.
        //application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
        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:.
    }


}

2 Answers

Hi Mark!

Please could you post your code? Please refer to the markdown cheatsheet to find out how!

-Luke

Thanks for commenting, added above.

You have commented out a piece of code in your appDelegate file. It should be the third line in the first function at the top of the file, and should look like this:

application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

Your code has it written like this:(as if it were a comment)

// application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

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

Hey Kyle,

Ack, that was actually me tinkering with it to see if that was causing the simulator to go black (since part of the tutorial involved a change on that line). I took the // out again and still have the simulator going black when it runs. Googling possible solutions again, but let me know if you see anything else that could cause this problem. Thanks a ton for looking and commenting!