Skip to content

Instantly share code, notes, and snippets.

@snown
Last active August 29, 2015 14:02
Show Gist options
  • Save snown/e9bd220d32fd4a53ba3d to your computer and use it in GitHub Desktop.
Save snown/e9bd220d32fd4a53ba3d to your computer and use it in GitHub Desktop.
A little extension to Array to allow prepending an item. This is just an experiment, not necessarily the right way to do it.
extension Array {
mutating func prepend(newitem: T) {
insert(newitem, atIndex: 0)
}
mutating func prepend(itemArray: Array) {
for (index, item) in enumerate(itemArray) {
insert(item, atIndex: index)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment