
It’s easy to add an element at the bottom of a stack of vertical cubes as long as there aren’t too many cubes. You can think of the difference between the two queues by visualizing Array as a vertical stack of cubes and Deque as a horizontal row of cubes. An array is only optimized for adding or removing elements at its end. Unlike an array, a deque is super efficient at inserting or removing elements from its beginning or its end. Now that you’re familiar with the starter project, you’ll learn about the new data structures available in the Swift Collections package, starting with Deque.ĭeque - pronounced “Deck”, derived from Double- Ended Queue - holds a sequence of values, just like an array. This will help set up a baseline of what the built-in types can do compared to the data structures available in the Swift Collections package. Each page creates one of the built-in data structures, then performs commonly-used operations on each.
#How to use icollections code
Run the code in each of the playground pages to check out the results.
#How to use icollections how to
The playground contains three pages: one for Deque, one for OrderedSet and one for OrderedDictionary.Įach page already contains code to demonstrate how to use the closely-matching data structures that Swift already contains: Array, Set and Dictionary, as well as KeyValuePairs, which you may not have heard of before. Note: This tutorial used Arena to create a Swift playground that incorporates a Swift package as a dependency. Checking Equality With OrderedDictionary.Swapping Elements Using OrderedDictionary.Adding Elements to an Existing OrderedSet.


Comparing the Performance of Deque Versus Array.Hide contents Getting Started With the Swift Collections Package
