December 2014
Beginner
300 pages
8h 9m
English
If you want to remove items from an array, you can use a number of methods in Swift. For example, you can remove the last item with removeLast():
raining.removeLast()
And you can remove an element at a specific index by using removeAtIndex(:atIndex):
var raining = ["cats","octopuses"] // cats, octopusesraining.insert("dogs", atIndex: 1)raining // cats, dogs, octopusesraining.removeAtIndex(1) // returns the element it removed "dogs"raining // cats, octopuses
Here’s what’s going on here:
1. You start with an array of two elements.
2. You insert an element at index 1.
3. Then you just remove the same item you added at index 1.
When removing elements from an array it is important to remember ...
Read now
Unlock full access