structPoint { var x =0.0, y =0.0 funcisToTheRightOfX(x: Double) -> Bool { returnself.x > x } } let somePoint =Point(x: 4.0, y: 5.0) if somePoint.isToTheRightOfX(1.0) { print("This point is to the right of the line where x == 1.0") } // 打印 "This point is to the right of the line where x == 1.0"
structPoint { var x =0.0, y =0.0 mutatingfuncmoveByX(deltaX: Double, ydeltaY: Double) { x += deltaX y += deltaY } } var somePoint =Point(x: 1.0, y: 1.0) somePoint.moveByX(2.0, y: 3.0) print("The point is now at (\(somePoint.x), \(somePoint.y))") // 打印 "The point is now at (3.0, 4.0)"