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 trialThomas Schmidt
2,511 Pointsbreakpoint Int
I have a question about the randomFact function. When I run my code I get a breakpoint error at the
let randomNumber = Int(unsignedRandomNumber)
It seems that when I return
factsArray[randomNumber]
I get a number like 140734746147408. I looked through my breakpoint error and it shows me that the
unsignedArrayCount = 10
unsignedRandomNumber = 8
but my
randomNumber = 140734746147408
``` Please help me out.
Thomas Schmidt
2,511 Points struct FactBook {
let factsArray = ["Array with 10 things in it"]
func randomFact() -> String {
let unsignedArrayCount = factsArray.count
let unsignedRandomNumber = arc4random_uniform(UInt32(unsignedArrayCount))
let randomNumber = Int(unsignedRandomNumber)
return factsArray[randomNumber]
}
}
This is what it looks like. Like I said the breakpoint error says unsignedArrayCount = 10, unsignedRandomNumber = {8}, and randomNumber = 140734746147408. Not sure what is going on here
Jhoan Arango
14,575 PointsEverything looks fine to me, but try this and see how it behaves. It shouldn't behave any different, since it's basically the same thing. But it's worth giving it a try.
struct FactBook {
let factsArray = ["Array with 10 things in it"]
func randomFact() -> String {
let unsignedArrayCount = UInt32(factsArray.count)
let unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
let randomNumber = Int(unsignedRandomNumber)
return factsArray[randomNumber]
}
}
If that does not work let me know, and we can look deeper into it.
I used your code in my sample of the same app, and it worked perfectly.
Thomas Schmidt
2,511 PointsI changed the code to what you said and it still didn't work. But I decided to just start over and make a new projects and now it seems to work the only difference from my last one is I changed the type of phone to used in the simulator. The video says to use iPhone 5 but I used iPhone 6s. I don't know what happened but it works. Thanks a lot Jhoan.
1 Answer
Adam Stringfellow
9,107 PointsHi Thomas,
The current version of Xcode makes it very easy to accidentally add breakpoints in your code. Press CMD+7 to display the breakpoint navigator on the left panel. Now just select and delete all your breakpoints. Alternatively if you can delete breakpoints by right clicking the highlighted line numbers in your code and selecting delete.
Jhoan Arango
14,575 PointsJhoan Arango
14,575 PointsHello Thomas :
Would you mind if you show your code ? This way I can help you better.