var middle: (Double, Double) {
get{
return (length / 2 , breadth / 2 )
}
set(axis){
no1 = axis. 0 - (length / 2 )
no2 = axis. 1 - (breadth / 2 )
}
}
}
var result = sample()
println(result.middle)
result.middle = (0.0, 10.0)
println(result.no1)
println(result.no2)
When we run the above program using playground, we get the following result:
(150.0, 75.0)
- 150.0
- 65.0
When a computed property left the new value as undefined, the default value will be set
for that particular variable.
Computed Properties as Read-Only Properties
A read-only property in computed property is defined as a property with getter but no
setter. It is always used to return a value. The variables are further accessed through a '.'
Syntax but cannot be set to another value.
class film {
var head = ""
var duration = 0.0
var metaInfo: [String:String] {
return [
"head": self.head,