/*To avoid having to call count on an array, Swift allows developers to simply call removeLast to remove the last item in an array.*/
var animalArray: [String] = ["Dog", "Cat", "Fish", "Owl" ]
animalArray.removeLast()
//animalArray now contains 3 items, "Owl" has been removed.
/*Again, if you wish to save the value before you remove it:*/
let stringAnimal = animalArray.removeLast()
//Saves "Owl" (which was the last item in the array) to the string constant stringAnimal and also removes it from the array.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.