Swift - Using class computed properties to return tuples

Description

Using class computed properties to return tuples

Demo

class Rectangle { 
    var width: Double = 0.0 
    var height: Double = 0.0 

    var center  : (x: Double, y: Double) { 
        return (width / 2, height / 2) 
    } /*from w w  w  .  j a  v a  2 s .  co  m*/
} 
let rect = Rectangle() 
rect.width = 3.0 
rect.height = 4.5 
print(rect.center) // (x: 1.5, y: 15)

Result

Related Topic