The focus of this function should be on the calculation.
For the general properties, either directly to save one, or directly read one, 计算属性
you can be set according to the content, make some modifications or calculations, such as:
Import Uikitclass Sample { var no1 = 0.0, NO2 = 0.0 var length = 300.0, breadth = 150.0 var middle: (Double,dou BLE) { get { return (LENGTH/2, BREADTH/2) } //If no parentheses are added, the default is set (NewValue) {} set { //can be in SE The T method dynamically modifies other properties and this property no1 = newvalue.0-(LENGTH/2) NO2 = newvalue.1-(BREADTH/2) } //supplemental // The Set method can also be written as //Set (value) { // no1 = value.0-(LENGTH/2) // NO2 = value.1-(BREADTH/2) // } }}var result = sample () print (result.middle) Result.middle = (0.0, 10.0) print (result.no1) print (RESULT.NO2) var result = sample () print (result.middle) Result.middle = (0.0, 10.0) print (result.no1) print (RESULT.NO2)
Output Result:
(150.0, 75.0)
-150.0
-65.0
Understanding of computed attributes and previous additions to Swift