The concept of Protocols is same as that of Objective C. It provides a blue print for methods, properties.
e.g is like below
protocol TestProtocol
{
var simpleDesc: String {get}
func adjust()
}
the {get} followed by simpleDesc indicates that it is read only.
Protocols are like first class types, which means that they can be treated like other named types.
class SimpleProtocol2: ExampleProtocol
{
var SimpleDescription: String = “Another very simple class”
fun adjust()
{
simpleDescroption += “adjusted”
}
}
var protocolArray : [ExampleProtoocl] = [SimpleClass(), SimpleClasse(), Simpleclass()]
References:
No comments:
Post a Comment