In e.g. Java you can do something like this:
myFunction(new MyClass[]{myclass1, myclass2, myclass3})
Is there an equivalent in Swift?
I tried
myFunction([MyClass](myclass1,myclass2,myclass3))
and Xcode suggested to change it to
myFunction([MyClass](arrayLiteral: myclass1,myclass2,myclass3))
but the documentary (click) tells you not to call "arrayLiteral" directly.
Edit: The reason why I want to do this is a bit complicated:
I've got a class MyClass and created a bunch of instances that carry data: myclass1, myclass2, myclass3
init(name na:String, number nu:Int, content c:String) {....}
These instances I want to add to an array, which I'm then using to create an instance of a second class MyOtherClass:
init(name n:String, someotherinfo s:String, myclassarray m:[MyClass]) {....}
Creating the instance:
var myotherclassthing = MyOtherClass(name:"Test", someotherinfo:"Bla", myclassarray: ??????????)
This instance of MyOtherClass I'm then passing from my main View to a second View via a segue.
varthat I'm never going to use. I guess I'm just used to passing the new array directly. Is there then even a difference between creating a newvarand creating and passing the array directly in Swift?var, 2. creating and passing the array directly. And you want to know if there is any difference between them or not. If I'm correctly getting into your question, then no, there isn't any difference. Essentially when you pass an array to another method, a complete new instance is actually passed.value&referencemore in Swift. Swift is designed keepingvaluetypes in mind. You see a lot ofstruct's in Swift.myFunction([myclass1, myclass2, myclass3]). You bracket a bunch of object using[ ], you create an instance ofArray. That's it.