How to create arraylist of object in swift

Trying to make the code as close to your example code, this is my answer (requires to have declared Country class somewhere:

var countryList : Array<Country> = Array()
var aBucket     : Country        = Country()
....
countryList.append(aBucket)

Hope this helps


You can do this using an Array. Take a look here for more information about arrays.

You can use the append(...) function to add objects.

var array = [Country]() //alternatively (does the same): var array = Array<Country>()
array.append(Country())
array.append(Country())

Tags:

Arrays

Swift