Protocol exampleprotocol{
var simpledescription:string{get}
Mutating func adjust ()
}
Class simpleclass:exampleprotocol{
var simpledescription:string = "A very simple class"
var anotherproperty:int = 69105
Func Adjust () {
Simpledescription + = "Now 100% requested"
}
}
var a = Simpleclass ()
Print (a.simpledescription)
A.adjust ()
Print (a.simpledescription)
struct simplestructure:exampleprotocol{
var simpledescription:string = "A Simple Structure"
Mutating func adjust () {
Simpledescription + = "(adjust)"
}
}
var B = simplestructure ()
Print (b.simpledescription)
B.adjust ()
Print (b.simpledescription)
Extension int:exampleprotocol{
var simpledescription:string{
Return "the number is \ (self)"
}
Mutating func adjust () {
Self + = 50
}
}
println (7.simpleDescription)
Extension string:exampleprotocol{
var simpledescription:string{
Return "My name is \ (self)"
}
Mutating func adjust () {}
}
Print ("xingxing". Simpledescription)
Swift--Protocol, extension