UnknownUser UnknownUser - 2 years ago 135
Swift Question

How to remove an element from an array in Swift

How can I unset/remove an element from an array in Apple's new language Swift?

Here's some code:

var animals = ["cats", "dogs", "chimps", "moose"]

How could the element
be removed from the array?

Answer Source

The let keyword is for declaring constants that can't be changed. If you want to modify a variable you should use var instead, e.g:

var animals = ["cats", "dogs", "chimps", "moose"]

animals.removeAtIndex(2)  //["cats", "dogs", "moose"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download