<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Adrian,</div><div class="">thanks, but don’t work :-(</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">import</span> Foundation</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">protocol</span> AreaProtocol {</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// required</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">func</span><span class="Apple-tab-span" style="white-space:pre">        </span>area() -> <span style="color: #703daa" class="">CGFloat</span></div><p style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 16px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// implemented in protocol extension</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">func</span><span class="Apple-tab-span" style="white-space:pre">        </span>volume( height:<span style="color: #703daa" class="">CGFloat</span> ) -> <span style="color: #703daa" class="">CGFloat</span></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// ....</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span><span style="color: #000000" class=""> </span>AreaProtocol<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">func</span><span class="Apple-tab-span" style="white-space:pre">        </span>volume( height:<span style="color: #703daa" class="">CGFloat</span> ) -> <span style="color: #703daa" class="">CGFloat</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #ba2da2" class="">return</span> height * <span style="color: #31595d" class="">area</span>()</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// ....</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// ....</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">protocol</span> CGPointSequence: <span style="color: #703daa" class="">Sequence</span>, <span style="color: #4f8187" class="">AreaProtocol</span> <span style="color: #ba2da2" class="">where</span> <span style="color: #703daa" class="">Element</span> == <span style="color: #703daa" class="">CGPoint</span> {}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span><span style="color: #000000" class=""> </span>CGPointSequence<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">func</span> area()<span class="Apple-tab-span" style="white-space:pre">        </span>-> <span style="color: #703daa" class="">CGFloat</span><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="color: #ba2da2" class="">return</span><span style="color: #000000" class=""> </span><span style="color: #272ad8" class="">0.0</span><span style="color: #000000" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span>// ... poligon area</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="text-decoration: underline ; color: #ba2da2" class="">e</span><span style="color: #ba2da2" class="">xtension</span><span style="color: #000000" class=""> </span><span style="color: #703daa" class="">Array</span><span style="color: #000000" class="">:</span><span style="text-decoration: underline ; color: #4f8187" class="">CGPointSequence</span><span style="color: #000000" class=""> {} </span>// !'CGPointSequence' requires the types 'Element' and 'CGPoint' be equivalent</div></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Il giorno 25 nov 2017, alle ore 09:11, Adrian Zubarev <<a href="mailto:adrian.zubarev@devandartist.com" class="">adrian.zubarev@devandartist.com</a>> ha scritto:</div><br class="Apple-interchange-newline"><div class=""><div class="">This is correct. None of your types does conform to your protocol because you never conformance explicitly. <div class=""><br class=""></div><div class="">The extenstion you wrote is just a conditional extension which says if the Self type conforms to AreaProtocol and the associated typed Element is a CGPoint then add the area method to it. Nothing more, nothing less.</div><div class=""><br class=""></div><div class="">Now you may think that you have to rewrite that extension to `extension Sequence : AreaProtocol where Element == CGPoint`, but that won't work because retroactively conforming protocols to other protocols is not supported yet. Nor are conditional conformances included yet, but they will in Swift 4.1 or 5.</div><div class=""><br class=""></div><div class="">You have one option left.</div><div class="">protocol MySequence : Sequence, AreaProtocol where Element == CGPoint {}</div><div class=""><br class=""></div><div class="">extension Array : MySequence {}</div><div class=""><br class=""></div><div class="">Then also conform other sequences you need to support that functionality.</div><div class=""><br class=""></div><div class="">Double check if the code compiles, I wrote it on my iPhone, but you get the idea now.</div><div class=""> <br class=""><div class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><p class="gmail_quote" style="">Am 25. November 2017 um 07:40:25, Antonino Ficarra via swift-users (<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>) schrieb:</p> <blockquote type="cite" class="gmail_quote"><span class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""></div><div class="">
<title class=""></title>
<div style="font-size: 14px;" class="">In this code example:</div>
<div style="font-size: 14px;" class=""><br class=""></div>
<div class="">
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">import</span>
Foundation</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">protocol</span>
AreaProtocol {</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(186, 45, 162);" class="">func</span> area() -> <span style="color: rgb(112, 61, 170);" class="">CGFloat</span></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 16px;" class=""><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// implemented in protocol extension</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> volume(
height:<span style="color: #703daa" class="">CGFloat</span> ) ->
<span style="color: #703daa" class="">CGFloat</span></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// ....</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span>
AreaProtocol <span style="" class="">{</span></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> volume(
height:<span style="color: #703daa" class="">CGFloat</span> ) ->
<span style="color: #703daa" class="">CGFloat</span> {</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">return</span> height
* <span style="color: #31595d" class="">area</span>()</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// ....</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// ....</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// conform CGPoint sequences to AreaProtocol</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">extension <span style="color: #703daa" class="">Sequence</span></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">where</span> Self
<span style="" class="">:</span>
AreaProtocol<span style="" class="">,</span>
<span style="color: #703daa" class="">Element</span> <span style="" class="">==</span> <span style="color: #703daa" class="">CGPoint</span></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">{</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span>
area() -> <span style="color: #703daa" class="">CGFloat </span>{</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">return</span>
<span style="color: #272ad8" class="">0.0</span> // ... poligon
area</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> p0 =
<span style="color: #703daa" class="">CGPoint</span>(x:
<span style="color: #272ad8" class="">0.0</span>, y: <span style="color: #272ad8" class="">0.0</span>)</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> p1 =
<span style="color: #703daa" class="">CGPoint</span>(x:
<span style="color: #272ad8" class="">2.0</span>, y: <span style="color: #272ad8" class="">0.0</span>)</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> p2 =
<span style="color: #703daa" class="">CGPoint</span>(x:
<span style="color: #272ad8" class="">2.0</span>, y: <span style="color: #272ad8" class="">2.0</span>)</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> p3 =
<span style="color: #703daa" class="">CGPoint</span>(x:
<span style="color: #272ad8" class="">0.0</span>, y: <span style="color: #272ad8" class="">2.0</span>)</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> poligon =
[<span style="color: #4f8187" class="">p0</span>,<span style="color: #4f8187" class="">p1</span>,<span style="color: #4f8187" class="">p2</span>,<span style="color: #4f8187" class="">p3</span>]</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span>
<span style="" class="">a =</span> <span style="color: #4f8187" class="">poligon</span><span style="" class="">.</span><span style="text-decoration: underline;" class="">a</span><span style="" class="">rea()</span>// !
Type '[CGPoint]' does not conform to protocol 'AreaProtocol'</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span>
<span style="" class="">v =</span> <span style="text-decoration: underline ; color: #4f8187" class="">p</span><span style="color: #4f8187" class="">oligon</span><span style="" class="">.volume(
height:</span><span style="color: #272ad8" class="">10.0</span>
<span style="" class="">)</span>// ! Value of type
'[CGPoint]' has no member 'volume'</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><br class=""></div>
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">
<div style="font-family: Helvetica;" class="">
An array of CGPoint is a CGPoint sequence? Why the array don't gets
automatic conformance to AreaProtocol?</div>
<div style="font-family: Helvetica;" class="">
How can conform an array of CGPoint to AreaProtocol?</div>
<div style="font-family: Helvetica;" class="">
<br class=""></div>
<div style="font-family: Helvetica;" class="">
Sorry for my bad english,</div>
<div style="font-family: Helvetica;" class="">
Antonino</div>
<div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div>
</div>
_______________________________________________<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></span></blockquote>
</div></div></div></blockquote></div><br class=""></body></html>