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 Swift Basics (retired) Control Flow For-In Loop

Danya Baron
Danya Baron
3,170 Points

Why is Xcode only printing out last item of array?

I am working on this in Swift 2. I'm trying to print out all the elements in this array, and when I display it, it only prints out Pickup laundry.

var todo = ["Return Calls", "Write blog", "Cook Dinner", "Pickup laundry"]

for element in todo { print(element) }

I'm not sure what I'm doing wrong. Also I cannot see the console in assistant editor, it does not show up.

3 Answers

Douglas Counts
Douglas Counts
10,060 Points

Those print calls are console calls. Open up the debugger panel at the bottom by clicking the down arrow there and pressing the run button. You will see all the lines, not just the last line like you do on the right. The right side only shows the last result as it is designed to be interactive while you code, the right panel isn't intended to be a printout. For that you need to open the debugger panel at the bottom that is normally closed on startup.

If you click the "Show Result" button on the right side of your playground then right click the box inside the playground and hit "Value History", you will see that the For loop did complete correctly.

Danya Baron
Danya Baron
3,170 Points

I actually just figured out how to do open the console, and it works properly. Thank you both!