Swift initialise empty array to store different structs later
<p>I have a couple of different types of structs (Promo &amp; Event). I'd like to create an empty array which gets populated with an array of each type depending on the outcome of an <code>if</code> statement.</p>

<p>So something like this:</p>

<pre><code>var dataArray:[Any] = []  // see options I've tried below 

if myTest == true {
    dataArray = [Promo, Promo, Promo]
} else {
    dataArray = [Event, Event, Event]    
}
</code></pre>

<p>I have tried using:</p>

<pre><code>1. var dataArray: [Any] = []
2. var dataArray: [AnyObject] = []
3. var dataArray: [Any] = [Any]()
4. var dataArray: [AnyObject] = [AnyObject]()
</code></pre>

<p>but when I try to store an array of <code>Promo</code> Structs in <code>dataArray</code> I get an error <code>Cannot assign value of type '[Promo]' to type '[Any]'</code> etc.</p>

<p>So, how do I initialise an array so that it can store a variety of (unknown) Structs. Or how do I modify my Structs to enable them to be stored in an array?</p>

<p>I'm really struggling to see what I'm doing wrong so any pointers would be v. helpful.</p>

<hr>

<p>Here are my Structs:
<strong>Promo.swift</strong></p>

<pre><code>import Foundation

struct Promo {

    // initialise the stored properties for use later
    let promoId : Int
    let date : NSDate
    let title: String
    let body: String
    let busName : String
    let busId : Int
    let categoryId: Int
    let featured: Bool

    // a universal init() method which has optional parameters
    init(promoId: Int,
         date: NSDate,
         title: String,
         body: String,
         busName: String,
         busId: Int,
         categoryId: Int,
         featured: Bool
        ){
        self.promoId = promoId
        self.date = date
        self.title = title
        self.body = body
        self.busName = busName
        self.busId = busId
        self.categoryId = categoryId
        self.featured = featured
    }
}

// allow us to compare structs
extension Promo: Equatable {}
func ==(lhs: Promo, rhs: Promo) -&gt; Bool {
    return lhs.promoId == rhs.promoId
        &amp;&amp; lhs.date == rhs.date
        &amp;&amp; lhs.title == rhs.title
        &amp;&amp; lhs.body == rhs.body
        &amp;&amp; lhs.busName == rhs.busName
        &amp;&amp; lhs.busId == rhs.busId
        &amp;&amp; lhs.categoryId == rhs.categoryId
        &amp;&amp; lhs.featured == rhs.featured
}
</code></pre>

<p><strong>Event.swift</strong></p>

<pre><code>import Foundation

struct Event {

    // initialise the stored properties for use later
    let eventId : Int
    let date : NSDate
    let title: String
    let body: String
    let busName : String
    let busId : Int
    let categoryId: Int

    // a universal init() method which has optional parameters
    init(eventId: Int,
         date: NSDate,
         title: String,
         body: String,
         busName: String,
         busId: Int,
         categoryId: Int
        ){
        self.eventId = eventId
        self.date = date
        self.title = title
        self.body = body
        self.busName = busName
        self.busId = busId
        self.categoryId = categoryId
    }
}
</code></pre>