<div dir="ltr">That is a new feature in Swift 3.1.<div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 19, 2017 at 5:32 PM, 曹剑楠 <span dir="ltr">&lt;<a href="mailto:frogcjn@163.com" target="_blank">frogcjn@163.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Sorry about my typo:<div><br></div><div><span class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><div style="word-wrap:break-word"><div><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Album</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div>    <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span> sectionedMediaIte<wbr>mInfos: [<span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Sectioned</span>&lt;<span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">MediaItemInfo</span>&gt;]?}<div><br></div><div><div style="margin:0px;line-height:normal"><br></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Sectioned&lt;Item&gt; : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">SectionProtocol</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> title: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">String</span><span style="font-variant-ligatures:no-common-ligatures">?</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Item</span><span style="font-variant-ligatures:no-common-ligatures">]</span></div><div style="margin:0px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586m_715390691247048198webkit-block-placeholder"></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">items</span><span style="font-variant-ligatures:no-common-ligatures"> = </span><span style="font-variant-ligatures:no-common-ligatures">[]</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">title</span><span style="font-variant-ligatures:no-common-ligatures"> = nil</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></span></div></span></div></div></blockquote></div></div></div></div></div></div><br></div></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">extension</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Array</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">where</span><span style="font-variant-ligatures:no-common-ligatures"> Element == Sectioned {</span></div><span class=""><p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586webkit-block-placeholder"></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> itemsCount: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> reduce(0) { (result, section) </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">in</span><span style="font-variant-ligatures:no-common-ligatures"> result + section.items.count }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586webkit-block-placeholder"></p></span><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Element</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Item</span><span style="font-variant-ligatures:no-common-ligatures">] {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">self</span><span style="font-variant-ligatures:no-common-ligatures">.flatMap { $0.items }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">Allow extension Array with strict its Element with a struct type (may be generic) is highly wanted feature.</span></div><div><div class="h5"><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><blockquote type="cite"><div>在 2017年2月20日,上午7:28,曹剑楠 &lt;<a href="mailto:frogcjn@163.com" target="_blank">frogcjn@163.com</a>&gt; 写道:</div><br class="m_-160934208573440586Apple-interchange-newline"><div><div style="word-wrap:break-word"><div><br></div><div>OK, my fault. That solved the problem.</div><div><br></div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures">Element</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures">SectionItemType</span><span style="font-variant-ligatures:no-common-ligatures">]</span></div></span></div></div></blockquote></div></div></div></blockquote><div><br></div>I should use this.<br><br></div><div>How about to allow using generic type Section directly instead of declare a protocol</div><div><br></div><div>```Swift</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">extension</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Array</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">where</span><span style="font-variant-ligatures:no-common-ligatures"> Element == Section {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> itemsCount: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> reduce(0) { (result, section) </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">in</span><span style="font-variant-ligatures:no-common-ligatures"> result + section.items.count }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures">Element</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures">SectionItemType</span><span style="font-variant-ligatures:no-common-ligatures">] {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">self</span><span style="font-variant-ligatures:no-common-ligatures">.flatMap { $0.items }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">```</span></div><br><div><blockquote type="cite"><div>在 2017年2月20日,上午7:14,Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; 写道:</div><br class="m_-160934208573440586Apple-interchange-newline"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 19, 2017 at 5:04 PM, 曹剑楠 via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">Hi All,</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">I’m coding for section like data structure. </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">For example:</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">I have an Album struct, which has many MediaItems.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">It has a sectioned property called &quot;sectionedMediaItemInfos&quot;, which is an array of sections.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><div><span style="font-variant-ligatures:no-common-ligatures">Each section represents for a disc, and </span>has an &quot;items&quot; array contains all MedaItems in that disc.</div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div>The define code is like:</div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">```Swift</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Album</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">let</span><span style="font-variant-ligatures:no-common-ligatures"> sectionedMediaItemInfos: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Sectioned</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">MediaItemInfo</span><span style="font-variant-ligatures:no-common-ligatures">&gt;]?</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div><br></div><div><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Sectioned&lt;Item&gt; : </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">SectionProtocol</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">let</span><span style="font-variant-ligatures:no-common-ligatures"> title: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">String</span><span style="font-variant-ligatures:no-common-ligatures">?</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">let</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Item</span><span style="font-variant-ligatures:no-common-ligatures">]</span></div><div style="margin:0px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586m_715390691247048198webkit-block-placeholder"></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">items</span><span style="font-variant-ligatures:no-common-ligatures"> = </span><span style="font-variant-ligatures:no-common-ligatures">[]</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">title</span><span style="font-variant-ligatures:no-common-ligatures"> = nil</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">protocol</span><span style="font-variant-ligatures:no-common-ligatures"> SectionProtocol {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">associatedtype</span><span style="font-variant-ligatures:no-common-ligatures"> SectionItemType</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [SectionItemType] { </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">get</span><span style="font-variant-ligatures:no-common-ligatures"> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">```</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">Now I want to define some extra properties for sections array</span>, like</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">&quot;sectionMediaItemInfos&quot;.&quot;items<wbr>Count&quot; that count all items in each sections.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">So I can write that extension:</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px">```Swift</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">extension</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Array</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">where</span><span style="font-variant-ligatures:no-common-ligatures"> Element : SectionProtocol {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586m_715390691247048198webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> itemsCount: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">reduce</span><span style="font-variant-ligatures:no-common-ligatures">(0) { (result, section) </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">in</span><span style="font-variant-ligatures:no-common-ligatures"> result + section.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">items</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#3495af">count</span><span style="font-variant-ligatures:no-common-ligatures"> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">```</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">So I can get my itemsCount with code like:</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">```Swift</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">album.sectionedMediaItemInfos.<wbr>itemsCount</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">```</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">That looks good.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">Then I want to define code to return all items in this sectioned property.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">```Swift</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">extension</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Array</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">where</span> E<wbr>lement : SectionProtocol {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures">SectionProtocol</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures">SectionItemTy<wbr>pe</span><span style="font-variant-ligatures:no-common-ligatures">] {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">return</span><span style="font-variant-ligatures:no-common-ligatures"> .flatMap { $0.items }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">```</span></div></span></div></div></blockquote><div> </div><div>Sorry, I&#39;m reading this quickly, but I&#39;m confused as to why you&#39;re not writing `var items: [Element.SectionItemType]`. That seems to be what you want, no? `SectionProtocol.<wbr>SectionItemType` has no constraints and, even if the grammar allowed you to write it, would have to be equivalent to `Any`.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"></span></div><div style="margin:0px;line-height:normal">This doesn’t work. It reported as &quot;Cannot use associated type &#39;SectionItemType&#39; outside of its protocol&quot;</div></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">The only way to achieve my goals is to untyped the extended &quot;items&quot; property:</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">```Swift</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">extension</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Array</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">where</span> E<wbr>lement : SectionProtocol {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">Any</span><span style="font-variant-ligatures:no-common-ligatures">] {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#0433ff">self</span><span style="font-variant-ligatures:no-common-ligatures">.flatMap { $0.items }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">```</span></div></span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;">Which is not perfect for this case.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">So in this special case, I think allow use associated type outside of its protocol is necessary.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures">And we may allow define protocol with generic type. That would be more convenient.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">```Swift</span></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Album</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> sectionedMediaIte<wbr>mInfos: [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Sectioned</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">MediaItemInfo</span><span style="font-variant-ligatures:no-common-ligatures">&gt;]?</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div><br></div><div><div style="margin:0px;line-height:normal"><br></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Sectioned&lt;Item&gt; : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">SectionProtocol</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> title: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">String</span><span style="font-variant-ligatures:no-common-ligatures">?</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> items: [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Item</span><span style="font-variant-ligatures:no-common-ligatures">]</span></div><div style="margin:0px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_-160934208573440586m_715390691247048198webkit-block-placeholder"></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">items</span><span style="font-variant-ligatures:no-common-ligatures"> = </span><span style="font-variant-ligatures:no-common-ligatures">[]</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">title</span><span style="font-variant-ligatures:no-common-ligatures"> = nil</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></span></div></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">protocol</span><span style="font-variant-ligatures:no-common-ligatures"> SectionProtoco<wbr>l&lt;SectionItemType&gt; {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [SectionItemType] { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">get</span><span style="font-variant-ligatures:no-common-ligatures"> }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">public</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">extension</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Array</span> <span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">where</span> E<wbr>lement : SectionProtocol {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="color:rgb(4,51,255);font-variant-ligatures:no-common-ligatures">var</span><span style="font-variant-ligatures:no-common-ligatures"> items: [<font color="#0433ff">Element.</font></span>SectionItemType] {</div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">self</span><span style="font-variant-ligatures:no-common-ligatures">.flatMap { $0.items }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></span></div></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">```</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">Thank all!</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">Jiannan</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></div>