Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

how to remove item from list swift

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

// remove at specific index
animals.remove(at: 2)  //["cats", "dogs", "moose"]

// remove first element
animals.removeFirst() //["dogs", "moose"]

// remove last element
animals.removeLast() //["dogs"]

// remove at unknown index
if let index = animals.firstIndex(of: "dogs") {
    animals.remove(at: index)
}

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #item #list #swift
ADD COMMENT
Topic
Name
5+5 =