Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Add element to beginning of array

You can add an element to the beginning of an array by insert at an index.

var pastSearches: [String] = []
pastSearches.insert("hi")
print(pastSearches)
=> ["hi"]
pastSearches.insert("bye", at: 0)
=> ["bye", "hi"]