Assigning an array of structs to an array of protocols
<p>Let's say I have the following:</p>

<pre><code>protocol MyProtocol {
}

struct MyStruct: MyProtocol {
}

var s1 = MyStruct()
var s2 = MyStruct()
var s3 = MyStruct()

var structArray = [s1, s2, s3]
</code></pre>

<p>When I try to assign this array of structs to an array of protocols (that each struct in <code>structArray</code> conforms to):</p>

<pre><code>var protocolArray:[MyProtocol] = structArray
</code></pre>

<p>I get this error: <code>Cannot convert array of type '[MyStruct]' to specified type '[MyProtocol]'</code></p>

<p>I would expect that since each object in the array conforms to the protocol it would be ok to say that "an array of structs that conform to some protocol" is assignable to something that expects "an array of anything that conforms to that protocol". But maybe this doesn't apply when the type is "an array of " vs just "thing", if that makes any sense.</p>

<p>For example, this is valid:</p>

<pre><code>var p1:MyProtocol = s1
</code></pre>

<p>Because s1 conforms to <code>MyProtocol</code>. But if you use arrays then it doesn't seem to hold anymore.</p>

<p>Incidentally, this seems to work too:</p>

<pre><code>var p1Array:[MyProtocol] = [s1, s2, s3]
</code></pre>

<p>Presumably because the type of the array is determined to be <code>[MyProtocol]</code> and isn't predetermined by some previous variable (like in my example above).</p>

<p>So anyways, all this to ask: What's the best way around this? How can I assign an array of structs (that conform to some protocol) to another array whose type is just "an array of things that conform that protocol".</p>

<p>I'm fairly new to Swift so I may be missing something trivial.</p>