Swift - Make Arrays Of Structs
<p>I am trying to add structs to an array. I know it's possible. I have seen it in another post on the site. But I am wondering if there is any way to add structs to an array without creating variables.</p>

<p>For example:</p>

<pre><code>struct Person {
    var name: String
    var surname: String
    var phone: Int
    var isCustomer: Bool
}

var contacts: [Person] = []

var person1: Person = Person(name: "Jack", surname: "Johnson", phone: 2, isCustomer: false) 
var person2: Person = Person(name: "alex", surname: "a", phone: 3, isCustomer: false)

contacts.append(person1)
contacts.append(person2)

for contact in contacts {
    print("\(contact.name)")
}
</code></pre>

<p>In this code we use <code>person1</code> and <code>person2</code> to create a "contact". But if you have to create hundreds of contacts it is annoying to setup up all these variables.</p>

<p>What I tried is this:</p>

<pre><code>struct Person {
    var name: String
    var surname: String
    var phone: Int
    var isCustomer: Bool
}

var contacts: [Person] = []

Person(name: "Jack", surname: "Johnson", phone: 2, isCustomer: false)

contacts.append(Person) // Here I get this error: "Cannot convert value of type '(Person).Type' (aka 'Person.Type') to expected argument type 'Person'
</code></pre>

<p>Is there any way to add structs to an array without creating variables? </p>