Remove All Elements From Array

In this short Swift code example we will learn how:

  • Initialize an Array with 5 elements in Swift
  • How to remove all elements from an Array
// Initialize Array with 5 elements
var myArray = [1,2,3,4,5]

// Print Array contents to preview
print(myArray)

// Remove all elements from Array
myArray.removeAll()

// Print Array contents to preview
print(myArray)

[raw_html_snippet id=”cookbookpagecoursesheader”]

Unit Testing Swift Mobile App

Apply Test-Driven Development(TDD) process to iOS mobile app development in Swift Preview this video course.