The removeFirst()
method in Swift is used to remove the first element of a set. The order of a set is different. The first element that appears in the first position of a set is not necessarily the first element.
set.removeFirst()
This method doesn't take any parameters.
Thi method returns the first removed element.
Let's look at the code below:
// create some setsvar names: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]var workers: Set = ["Dorothy", "Stephen", "Jane"]var numbers: Set = [1, 2, 3, 4, 5, 7, 8, 9, 10]// pop and return first elementprint(names.removeFirst())print(names.removeFirst())print(workers.removeFirst())print(numbers.removeFirst())
removeFirst()
method to remove the first elements of the sets and print to the console.