class关键字定义类class 类名 {
// 定义属性和方法
} class VideoMode {
var resolution = Resolution()
var interlaced = false
var frameRate = 0.0
var name: String?
}() let someVideoMode = VideoMode()print("The width of someResolution is \(someVideoMode.interlaced)").下去来访问子属性print("The width of someVideoMode is \(someVideoMode.resolution.width)")someVideoMode.resolution.width = 1280
print("The width of someVideoMode is now \(someVideoMode.resolution.width)")//定义一个VideoMode类的对象
let tenEighty = VideoMode()
tenEighty.resolution = hd
tenEighty.interlaced = true
tenEighty.name = "1080i"
tenEighty.frameRate = 25.0
//定义一个常量等于上面的类的对象
let alsoTenEighty = tenEighty
alsoTenEighty.frameRate = 30.0
//同时改变
print("The frameRate property of tenEighty is now \(tenEighty.frameRate)")if tenEighty === alsoTenEighty {
print("tenEighty and alsoTenEighty refer to the same VideoMode instance.")
}class Vehicle {
var currentSpeed = 0.0
var description: String {
return "traveling at \(currentSpeed) miles per hour"
}
func makeNoise() {
}
}class Bicycle: Vehicle {
var hasBasket = false
}override 关键字class Train: Vehicle {
override func makeNoise() {
print("Choo Choo")
}
}final var , final func , final class func