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 - Swift Tutorial
From the course: Swift 5 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Gathering inventory with collections24s
-
(Locked)
Swift arrays4m 27s
-
(Locked)
Core array methods6m 47s
-
(Locked)
Swift dictionaries5m 39s
-
Core dictionary methods7m 6s
-
(Locked)
Working with sets4m 12s
-
(Locked)
Core set methods3m 35s
-
(Locked)
Swift tuples5m 10s
-
Challenge: Merchant shop32s
-
(Locked)
Solution: Merchant shop5m 19s
-
(Locked)
-
-
-
-
-