You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TSPL.docc/LanguageGuide/OpaqueTypes.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -621,6 +621,29 @@ if let downcastTriangle = vertical.shapes[0] as? Triangle {
621
621
622
622
For more information, see <doc:TypeCasting#Downcasting>.
623
623
624
+
### Existential Of Composed Protocol Type
625
+
626
+
An existential can also creating by writing `any` before a composed protocol type (see <doc:Protocols#Protocol-Composition>). This creates a box which holds a structure, class or enum that conforms to all the protocols listed.
627
+
628
+
```
629
+
protocol Named {
630
+
var name: String { get }
631
+
}
632
+
protocol Aged {
633
+
var age: Int { get }
634
+
}
635
+
struct Person: Named, Aged {
636
+
var name: String
637
+
var age: Int
638
+
}
639
+
struct Dog: Named, Aged {
640
+
var name: String
641
+
var age: Int
642
+
var breed: String
643
+
}
644
+
var family: [any (Name & Aged)]
645
+
```
646
+
624
647
## Differences Between Opaque Types and Boxed Protocol Types
0 commit comments