[swift-users] Existentials in Swift
Toni Suter
tonisuter at me.com
Mon Nov 21 04:09:09 CST 2016
Hi everyone,
I am trying to understand existentials in Swift. I understand that in the
following code, P1 & P2 is an existential type, because it supports values
from all types that conform to both P1 and P2.
protocol P1 {}
protocol P2 {}
var x: P1 & P2
However, this raises a few questions for me:
1. In the following code, is x also an existential?
protocol P {}
var x: P
The proposals / blog posts that I read always talk about the protocol composition syntax,
but to me, this is the same as the first example, just with only a single protocol requirement.
2. Are Any and AnyObject also existentials?
So far, my understanding is:
Any is an existential with no requirements
AnyObject is an existential with only a class requirement
3. Why can I not extend Any / AnyObject?
For example, AnyObject is a protocol defined in the standard library. Why is it not extensible?
Thanks and best regards,
Toni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161121/c04264ab/attachment.html>
More information about the swift-users
mailing list