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 Creating a Data Model Finishing Up Our Model

Arjun Jain
Arjun Jain
2,047 Points

Thread Break issue

I'm working on the FunFacts program and tried to edit it so that it would not repeat facts. When I try running the app, I just see the title screen, and in my code there is a "Thread Breakpoint" that shows up.

Some of the things I added to my FactBook struct:

var countCheck = [-1]

mutating func randomFact() -> String {
    var arrayCount = UInt32(factsArray.count)

    var randomNumber = Int(arc4random_uniform(arrayCount))
    while contains(countCheck, randomNumber)
    {
        randomNumber = Int(arc4random_uniform(arrayCount))
    }

    countCheck.append(randomNumber)
    return factsArray[randomNumber]
}

func gameOver() -> Bool {
    return ((countCheck.count - 1) == factsArray.count)
}

My ViewController file-- note I changed "let factBook = FactBook()" to "var factBook = FactBook()" because it was throwing errors due to the mutating function I added to the struct.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var funFactLabel: UILabel!

var factBook = FactBook()

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

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

@IBAction func showFunFact() {
        funFactLabel.text = factBook.randomFact()
}

}

2 Answers

Stone Preston
Stone Preston
42,016 Points

its possible you accidently set a breakpoint. press command + y to disable all breakpoints and try running again. If you would like to remove the breakpoint completely press command + 7 and then right click on the breakpoint in the navigator and delete it. if that doesnt work, can you post the stuff that comes up in your console when the app breaks

Arjun Jain
Arjun Jain
2,047 Points

Sweet! That is exactly what happened. Thank you!

I had the same issue, thanks man!

Same thing here! Thanks for your help, Stone. I don't know how I enabled or set a breakpoint :-S

Chris Hedstrom
Chris Hedstrom
3,024 Points

Thank you for posting this solution, helped me too. I had exactly the same break point issue and it was driving me nuts.