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 trialStian Andreassen
523 PointsPrint arrays to label?
Hi,
I'm trying to learn about arrays, and put them to use in a simple app I'm playing around with.
I have a array, and want to display all the content of that array in a UILabel
. But I can't get it to work. Is there a video here on Treehouse that includes this part in an actual app? Or can someone help me out with this?
-Thanks
1 Answer
Ian Billings
Courses Plus Student 7,494 PointsHi Stian,
This very much depends on the type of objects in the array. If it is the standard types e.g. String, Int etc. You can use String interpolation to get the string representation of the array and assign that to the labels text property.
textLabel.text = "\(array)"
However, if its array of custom objects its a bit more tricky to get a proper String representation as it involves protocols which is a bit further down the track.
Hope that helps
Ian