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 trialmahi
7,137 PointsJust experimenting. Need some help.
after making a struct similar to the video, i wanted to experiment something. As am a bit familiar with FOR LOOP from prior experience, i used it in here to display all the values of the string one by one on each click of the button. But when I click the button, it jumps directly to the last value of the string.
import UIKit
class ViewController: UIViewController {
var factModel = FactModel()
@IBOutlet weak var funFactLabel: UILabel!
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() {
for fact in factModel.facts{
funFactLabel.text = fact
}
}
}
1 Answer
Silviu B.
3,111 PointsI think the problem is inside your showFunFact(). If you want to append the string, you might want to try inside your loop the following code:
funFactLabel.text.stringByAppendingString(fact)
mahi
7,137 Pointsi got my answer from the next videos. Anyways thanks a lot!!
mahi
7,137 Pointsmahi
7,137 Pointstried using C for loop swell, but isn't working
}