Files
SwiftStudy/11 方法.playground/Contents.swift

42 lines
677 B
Swift

import Cocoa
class Car {
static var cout = 0
init() {
Car.cout += 1
}
static func getCount() -> Int {cout}
}
let c0 = Car()
let c1 = Car()
let c2 = Car()
// 3
print(Car.getCount())
struct Point {
var x = 0.0, y = 0.0
mutating func moveBy(deltaX: Double, deltaY: Double) {
x += deltaX
y += deltaY
// self = Point(x: x + deltaX, y: y + deltaY)
}
}
enum StateSwitch {
case low, middle, high
mutating func next() {
switch self {
case .low:
self = .middle
case .middle:
self = .high
case .high:
self = .low
}
}
}