Instance Method

popFirst()

Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.

Declaration

mutating func popFirst() -> Dictionary<Key, Value>.Element?

Return Value

The first key-value pair of the dictionary if the dictionary is not empty; otherwise, nil.

Discussion

The first element of the dictionary is not necessarily the first element added. Don’t expect any particular ordering of key-value pairs.

Complexity: Averages to O(1) over many calls to popFirst().

See Also

Excluding Elements

func dropFirst(Int) -> Slice<Dictionary<Key, Value>>

Returns a subsequence containing all but the given number of initial elements.

func drop(while: ((key: Key, value: Value)) -> Bool) -> Slice<Dictionary<Key, Value>>

Returns a subsequence by skipping elements while predicate returns true and returning the remaining elements.

func dropLast(Int) -> Slice<Dictionary<Key, Value>>

Returns a subsequence containing all but the specified number of final elements.