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 Structs as Data Models Structs or Classes

Arman Arutyunov
Arman Arutyunov
21,900 Points

Guys my iPhone simulator doesn't show anything on the screen + I have an error in the code but it's the same as Pasan's

FIRST PROBLEM - error in ViewController.swift on line 14

let factModel = factModel()

which says "Variable used within its own initial value"

Does anybody know what does it mean? Pasan's code is the same but he doesn't have an error

I can show the code

This is my FactsModel.swift

//
//  FactsModel.swift
//  FunFacts
//
//  Created by Arman on 14/03/16.
//  Copyright © 2016 Treehouse. All rights reserved.
//

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." ]
}

And this is ViewController.swift

//
//  ViewController.swift
//  FunFacts
//
//  Created by Arman on 13/03/16.
//  Copyright © 2016 Treehouse. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var funFactLabel: UILabel!
    let factModel = factModel()

    override func viewDidLoad() {
        super.viewDidLoad()
        funFactLabel.text = factModel.facts[0]
    }

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

    @IBAction func showFunFact() {

        funFactLabel.text = factModel.facts[1]
    }

}

And the SECOND PROBLEM - iPhone simulator firstly didn't show anything on the screen like there was no code at all. My button and label just disappeared after I wrote this code. And now it doesn't even turn on! Says "Build Failed" and that's it.

PLEASE HELP!!!

Xcode Version 7.2.1 (7C1002)

Arman Arutyunov
Arman Arutyunov
21,900 Points

Someone helped me with my error. Just had to capitalise FactModel like this:

let factModel = FactModel()

But the simulator issue is still the same. It doesn't work. The screen of the app is white.

Please help

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Arman Arutyunov,

Are you getting a runtime error (the app crashes when you run it)? If so, what does the debugger say? If this is not the case, and your screen is just blank, make sure the text of your label is set to a dark color and not white!

Good Luck

Arman Arutyunov
Arman Arutyunov
21,900 Points

it crashes and says

"Could not launch "Fun Facts"

cannot attach to process due to System Integrity Protection"

I don't know what it means, do you?