Recall & Review
beginner
What does the
append() method do in a Swift array?It adds a new element to the end of the array, increasing its size by one.
Click to reveal answer
beginner
How do you insert an element at a specific position in a Swift array?
Use the
insert(_:at:) method, specifying the element and the index where you want to add it.Click to reveal answer
beginner
What happens when you use
remove(at:) on a Swift array?It removes the element at the specified index and shifts the remaining elements to fill the gap.
Click to reveal answer
beginner
If you want to remove the last element of a Swift array, which method do you use?
Use
removeLast() to remove and return the last element of the array.Click to reveal answer
intermediate
Can you append multiple elements to a Swift array at once? If yes, how?
Yes, use the
append(contentsOf:) method with another array or sequence of elements.Click to reveal answer
Which method adds a single element to the end of a Swift array?
✗ Incorrect
The append() method adds one element to the end of the array.
How do you add an element at index 2 in a Swift array named 'fruits'?
✗ Incorrect
Use insert(_:at:) to add an element at a specific index.
What does
remove(at: 0) do to an array?✗ Incorrect
remove(at: 0) removes the element at index 0, which is the first element.
Which method removes and returns the last element of a Swift array?
✗ Incorrect
removeLast() removes and returns the last element.
How can you add multiple elements to a Swift array at once?
✗ Incorrect
append(contentsOf:) adds multiple elements from another collection.
Explain how to add, insert, and remove elements in a Swift array with examples.
Think about how you add things to a list, put things in the middle, or take things out.
You got /4 concepts.
Describe the difference between
append() and insert(_:at:) in Swift arrays.One adds to the end, the other lets you choose the spot.
You got /4 concepts.