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 ww .  j a  v a 2 s .  c  om
} 
let rect = Rectangle() 
rect.width = 3.0 
rect.height = 4.5 
print(rect.center) // (x: 1.5, y: 15)

Result

Related Topic