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

Sort array

In my app i have got 8 UITextfields placed horizontally. My UITextfields can only contain one letter, sort of like Scrabble. And when the user types in a letter, the letter gets appended to an array. I have then managed to join all of the strings, so the array displays a word made of those appended letters. If i write "T" "O" "M" from the left corner it says "You wrote "TOM". But that is only because i type in the "T" first then the "O" and "M". The word that is displayed is depending on which letter that gets typed first, and not the letter´s actual position.

Is there a way I can sort an array to display the letter from left to right, not depending on which letter gets typed in first?

1 Answer

rather than appending, the textfield action should replace an element at a set index. So you can just make a mutable array with 8 placeholders, then entering text will replace whatever is in the position associated with that field.

Thanks!