struct Resolution {
var width = 0
var height = 0
func test(){
println("test")
}
}
//所有结构体都有一个自动生成的成员逐一构造器,用于初始化新结构体实例中成员的属性
let vga = Resolution(width:640, height: 480)
let someResolution = Resolution()
println(vga.width)
println(someResolution.width)
someResolution.test()
//这样写错误
//someResolution.width = 23
class VideoMode {
var resolution = Resolution()
var interlaced = false
var frameRate = 0.0
var name: String?
}
let someVideoMode = VideoMode()
//Swift 允许直接设置结构体属性的子属性
someVideoMode.resolution.width = 12880
println(someVideoMode.resolution.width)
//类是引用类型,引用的是已存在的实例本身而不是其拷贝。
let hd = Resolution(width: 1920, height: 1080)
let tenEighty = VideoMode()
tenEighty.resolution = hd
tenEighty.interlaced = true
tenEighty.name = "1080i"
tenEighty.frameRate = 25.0
let alsoTenEighty = tenEighty
alsoTenEighty.frameRate = 30.0
if tenEighty === alsoTenEighty {
println("tenEighty 与 alsoTenEighty 是等价的")
}