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
Hamza Ansari
34 PointsHow do I re-write this line into Swift?
I don't know how to re-write this in Swift, because I believe it is in Objective-C. Could someone re-write it for me?
yourLabelName.text = [[NSString] stringWithFormat:@"The number of votes for Crepes is %d", voteCount1["votes"]];
2 Answers
Pavel Fomchenkov
20,897 PointsyourLabelName.text = "The number of votes for Crepes is \(voteCount1["votes"])"
spirosraptis
13,864 PointsIf you what you ask is how to set the text property of a UILabel here's a way in Swift:
var voteCount1 = NSDictionary(objectsAndKeys: 2,"votes");
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.text = "The number of votes for Crepes is " + String(voteCount1["votes"]! as Int);