Junior
To which types do protocols in Swift belong?
sobes.tech AI
Answer from AI
Marker Protocols.
// Example of Marker Protocol
protocol Identifiable {
// Simply indicates that the type is identifiable, without any requirements for methods or properties.
}
Associated Type Protocols.
protocol Container {
associatedtype Item
mutating func append(_ item: Item)
var count: Int { get }
subscript(i: Int) -> Item { get }
}
Protocols with requirements for methods and properties.
protocol Resizable {
func resize(to size: CGSize)
var currentSize: CGSize { get set }
}
These three types describe the main categories of protocols in Swift by their purpose and functionality.