<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You can do something like this:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span> <span style="color: #703daa" class="">Collection</span> <span style="color: #ba2da2" class="">where</span> Element: Collection, Index == Element.Index {</div><p style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">subscript</span><span style="color: #000000" class="">(i: </span>Index<span style="color: #000000" class="">, j: </span>Index<span style="color: #000000" class="">) -> </span>Element<span style="color: #000000" class="">.</span>Element<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">get</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>[i][j] }</div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span> <span style="color: #703daa" class="">MutableCollection</span> <span style="color: #ba2da2" class="">where</span> Element: MutableCollection, Index == Element.Index {</div><p style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">subscript</span><span style="color: #000000" class="">(i: </span>Index<span style="color: #000000" class="">, j: </span>Index<span style="color: #000000" class="">) -> </span>Element<span style="color: #000000" class="">.</span>Element<span style="color: #000000" class=""> {</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">get</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>[i][j] }</div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">set</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>[i][j] = newValue }</div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">Now you can say:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">var</span> a: [[<span style="color: #703daa" class="">Int</span>]] = [[<span style="color: #272ad8" class="">1</span>,<span style="color: #272ad8" class="">0</span>,<span style="color: #272ad8" class="">0</span>],[<span style="color: #272ad8" class="">0</span>,<span style="color: #272ad8" class="">1</span>,<span style="color: #272ad8" class="">0</span>],[<span style="color: #272ad8" class="">0</span>,<span style="color: #272ad8" class="">0</span>,<span style="color: #272ad8" class="">1</span>]]</div><div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class="">print<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">a</span><span style="color: #000000" class="">[</span><span style="color: #272ad8" class="">2</span><span style="color: #000000" class="">,</span><span style="color: #272ad8" class="">2</span><span style="color: #000000" class="">])</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: #4f8187" class="">a</span>[<span style="color: #272ad8" class="">2</span>,<span style="color: #272ad8" class="">2</span>] = <span style="color: #272ad8" class="">5</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class="">print<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">a</span><span style="color: #000000" class="">[</span><span style="color: #272ad8" class="">2</span><span style="color: #000000" class="">,</span><span style="color: #272ad8" class="">2</span><span style="color: #000000" class="">])</span></div></div><div class=""><br class=""></div><div class="">Extending the generic protocols instead of concrete types is usually better. Look at the protocols that define the API of the Array you are interested in and extend those underlying protocols.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 30, 2017, at 3:19 AM, Trevör ANNE DENISE via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I am trying to extend a 2D array, doing something like this:<br class="">extension Array where Element == Array<T: Comparable> {<br class="">}<br class=""><br class="">But this doesn't work ! Is there a way to do this ?<br class=""><br class="">Thank you ! :)<br class=""><br class="">Trevör<br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></body></html>