How to declare and initialise an array in Swift
问题 I have a class in Swift that I'm trying to write that has a variable of an array of objects. Is there a better way to write this? var myvar: Array<MyClass> = Array<MyClass>() Without the bit after the = sign, the compiler complains about my AppDelegate having no initializers. The above way seems a bit lengthy (though it's no more terse than the c# equivalent, I guess). I'd just like to know if there's a shortcut. Thanks. 回答1: You can initialize the variable with an empty array: var myvar: