From the course: Swift 5 Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Core array methods

Core array methods

- [Instructor] The next step with arrays is learning how to dynamically manipulate them. Now, they come with several handy methods right out of the box, including ones we've already seen, like append, insert, remove, and sort, which is going to be a new one. Let's start by creating a new array. We're going to call this characterClasses. I'm going to use the concise syntax and let the compiler infer the type. So this is going to be an array of strings again. Ranger, Paladin, and Druid. And down at the third comment, I'm going to add a print statement so that we can see these change sort of in real time and know what's going on. To add a new item to the end of the array, we're going to say characterClasses.append newElement. Type String. And we're going to add a new class called Gunslinger. You can also use the += compound operator the exact same way. So we'll say characterClasses +=. This time we're going to add…

Contents