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 trialShelby Hanna
1,453 Points.append function vs. += : What is the difference?
Hello,
Im working through Swift basics and I came across the += for adding items to an array and then I learned about the .append function. Is there a difference? When would I use += vs. .append? Maybe it is just the context and I am to early in the process to see it clearly.
2 Answers
krilnon
1,458 PointsIt may be a little early in the process to have a good grasp on the differences. The main one in my mind is that +=
lets you add multiple new items at the same time. append
only lets you add one new item at a time, so you'd have to call it multiple times in a row to get the same effect as +=
.
Shelby Hanna
1,453 PointsAh thanks. That makes sense. Cheers!
Kaden Hesse
391 PointsKaden Hesse
391 Pointsthanks that helps