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)