<html><body><div id="edo-message"><div>1. Yes</div><div>2. Yes</div><div>3. I don't know the actual reason, but Any and AnyObject have special meaning to the compiler and objects implicitly "conform"" to them. Either the implementation doesn't support extending those types, or we explicitly decided that extending these implicit existentials was a bad idea (what could you even write in an extension in Any? You'd almost certainly have to cast it to Something. Extend Something instead.)<br><br>- Karl<br><style>#edo-signature img {max-width: 90%}</style><div id="edo-signature" style="font-family: 'Helvetica Neue','Helvetica',Helvetica,Arial,sans-serif;font:'-apple-system-body';"></div><br><div id="edo-link"></div></div></div><div id="edo-original"><div><br><br><blockquote type="cite" style="margin:1ex 0 0 0;border-left:1px #ccc solid;padding-left:0.5ex;"><div>On Nov 21, 2016 at 11:09 am, &lt;<a href="mailto:swift-users@swift.org">Toni Suter via swift-users</a>&gt; wrote:<br><br></div><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii">Hi everyone,<div class=""><br class=""></div><div class="">I am trying to understand existentials in Swift. I understand that in the</div><div class="">following code, P1 &amp; P2 is an existential type, because it supports values</div><div class="">from all types that conform to both P1 and P2.&nbsp;</div><div class=""><br class=""></div><div class="">protocol P1 {}</div><div class="">protocol P2 {}</div><div class="">var x: P1 &amp; P2</div><div class=""><br class=""></div><div class="">However, this raises a few questions for me:</div><div class=""><br class=""></div><div class=""><b class="">1. In the following code, is x also an existential?</b></div><div class="">protocol P {}</div><div class="">var x: P</div><div class=""><br class=""></div><div class="">The proposals / blog posts that I read always talk about the protocol composition syntax,</div><div class="">but to me, this is the same as the first example, just with only a single protocol requirement.</div><div class=""><br class=""></div><div class=""><b class="">2. Are Any and AnyObject also existentials?</b></div><div class="">So far, my understanding is:</div><div class="">Any is an existential with no requirements</div><div class="">AnyObject is an existential with only a class requirement</div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">3. Why can I not extend Any / AnyObject?</b></div><div class="">For example, AnyObject is a protocol defined in the standard library. Why is it not extensible?</div><div class=""><b class=""><br class=""></b></div><div class="">Thanks and best regards,</div><div class="">Toni</div>_______________________________________________
swift-users mailing list
<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="1">swift-users@swift.org</a>
<a dir="ltr" href="https://lists.swift.org/mailman/listinfo/swift-users" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="2">https://lists.swift.org/mailman/listinfo/swift-users</a>
</div></blockquote></div></div></body></html>