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) Collections Modifying an Array

Edwin Mhoy Silva Rifa
Edwin Mhoy Silva Rifa
2,631 Points

What is the difference between append and insert? - and when too use them?

Help med pls

2 Answers

Alan Johnson
Alan Johnson
7,625 Points

append always places the item at the end of the array, whereas insert places it at the given position within the array. You could certainly insert to the end of the array as well.

Here's a quick example that you can toss into a playground:

var arr = ["Zero", "Two"]

arr.insert("One", atIndex: 1)
arr

arr.append("Three")
arr

arr.insert("Four", atIndex: 4)
arr
Edwin Mhoy Silva Rifa
Edwin Mhoy Silva Rifa
2,631 Points

Thank you - Iยดm just asking, and hope you could answer :)

  • Do you thing its hard too make an app, and how long would it take to learn it :) ?

It depends on what you want your app do to. We have courses on to make two different apps with Swift.