在java中,我们可以像这样创建对象的arraylist:
ArrayList<Country> countryList = new ArrayList<Country>();
Country aBucket = new Country();
aBucket.setName("Canada");
aBucket.setCity("Ottawa");
countryList.add(aBucket);
Run Code Online (Sandbox Code Playgroud)
或者像这样:
ArrayList<Matrices> list = new ArrayList<Matrices>();
list.add( new Matrices(1,1,10) );
list.add( new Matrices(1,2,20) );
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能在SWIFT中获得相同的东西/替代品
mad*_*nny 39
您可以使用Array执行此操作.有关阵列的更多信息,请查看此处.
您可以使用该append(...)功能添加对象.
var array = [Country]() //alternatively (does the same): var array = Array<Country>()
array.append(Country())
array.append(Country())
Run Code Online (Sandbox Code Playgroud)
试图使代码尽可能接近您的示例代码,这是我的答案(需要在某处声明 Country 类:
var countryList : Array<Country> = Array()
var aBucket : Country = Country()
....
countryList.append(aBucket)
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助